Answers to exercise 2.1, a-f

Perl syntax

a.[A-Za-z]+
b.[a-z]*b
c..*([A-Za-z]+) \1.*
d.b+(ab+)*
e.^[0-9].* |[^\w\n][A-Za-z]+$
f..*\Wgrotto\W.*\Wraven\W.*|.*\Wraven\W.*\Wgrotto\W.*

grep syntax

a.[A-Za-z][A-Za-z]*
b.[a-z]*b
c..*\([A-Za-z][A-Za-z]*\) \1.*
d.bb*\(abb*\)*
e.^[0-9].* |[^a-zA-Z0-9 \n][A-Za-z][A-Za-z]*$
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].*

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