Answers to exercise 2.1, a-f

Perl syntax

a.[A-Za-z]+One or more capital or lower case letters
b.[a-z]*bZero or more lower case letters, followed b y a b.
c..*([A-Za-z]+) \1.*Zero or more characters, followed by one or more capital or lower case letters, followed by a space, followed by the same sequence of one or more capital or lower case letters, followed by zero or more characters.
d.b+(ab+)*One or more bs, followed optionally by an a followed by one or more bs, followed optionally by an a followed by one or more bs...
e.^[0-9].* |[^\w\n][A-Za-z]+$Beginning of line, a digit, zero or more characters, a space or anything that's not a letter or a number or a new line, followed by one or capital or lower case letters, end of line.
f..*\Wgrotto\W.*\Wraven\W.*|.*\Wraven\W.*\Wgrotto\W.*Zero or more characters, a non-word character, the sequence grotto, a non-word character, zero or more characters, a non-word character, the sequence raven, a non-word character, zero or more characters... all that OR: Zero or more characters, a non-word character, the sequence raven, a non-word character, zero or more characters, a non-word character, the sequence grotto, a non-word character, zero or more characters.

grep syntax

a.[A-Za-z][A-Za-z]*Any capital or lower case letter, zero or more capital or lower case letters.
b.[a-z]*bZero or more lower case letters, a b
c..*\([A-Za-z][A-Za-z]*\) \1.*Zero or more characters, a sequence of one capital or lower case letter followed by zero or more capital or lower case letterse, then a space, then the same sequence as before again, then zero or more characters.
d.bb*\(abb*\)*a b, zero or more bs, then optionally, an a followed by a b and zero or more bs, then optionally, an a followed by a b and zero or more bs...
e.^[0-9].*[^a-zA-Z0-9\n][A-Za-z][A-Za-z]*$Beginning of line, any digit, zero or more characters, any character that is not a letter or number or a newline, any capital or lower case letter, zero or more capital or lower case letters, end of line.
f..*[^A-Za-z0-9]grotto[^A-Za-z0-9]
.*[^A-Za-z0-9]raven[^A-Za-z0-9].*|
.*[^A-Za-z0-9]raven[^A-Za-z0-9]
.*[^A-Za-z0-9]grotto[^A-Za-z0-9].*
Zero or more characters, a non-alphanumeric, the sequence grotto, another non-alphanumeric, zero or more characters, a non-alphanumeric, the sequence raven, another non-alphanumeric, zero or more characters... all that OR: Zero or more characters, a non-alphanumeric, the sequence raven, another non-alphanumeric, zero or more characters, a non-alphanumeric, the sequence grotto, another non-alphanumeric, zero or more characters.

Note: As these are regular expressions for languages, I've included a lot of .* that you wouldn't need when using regular expressions for search in a program that returns any line containing a string matching the regular expression.

Back to exercises