Special Characters:
\r newline
\n newline
\t tab
\b backspace
\d digit \D not a digit
\w word character [0-9a-zA-Z_] \W not word character
\s whitespace character \S not whitespace
\b when not within a range, \b refers to a word boundary character (between a word and a non-word). \B is any non-boundary.
Optional, Greedy, Lazy, Etc:
(abc|def) matches abc or def
(abc|) matches abc or nothing
(abc)? also matches abc or nothing
Greedy v Lazy: .* will always match the minimum number of characters (that makes the whole regex work) if lazy and the maximum number of characters in a line if greedy. * is greedy; *? is lazy.
* is 0 or more
+ is 1 or more
Lookarounds:
foo(?=bar) positive lookahead. Will match the "foo" in "foobar" but won't match the "foo" in "foo".
foo(?!bar) negative lookahead. Will match the "foo" in "foobaz" but won't match the "foo" in "foobar".
(?<=bar)foo positive lookbehind. Will match the "foo" in "barfoo" but won't match the "foo" in "foo".
(?<!bar)foo negative lookbehind. Will match the "foo" in "bazfoo" but won't match the "foo" in "barfoo".
regular-expressions.info is your best friend
Note: \d matches 0-9, not 1-9. \w matches underscores in addition to letters and digits
if you include a "!" without escaping it, your shell might interpret that as a special character. Grep needs to see the ! and if you don't escape it, your shell might never give it to grep.
Explain why there isn't a difference between ^.*$ (greedy) and ^.*?$ (lazy)
Make a regular expression to match fooA but not fooAbar