The ’.’ isn’t working the way I expected.
Here are some tips for using ‘.’:
- A common mistake is to place the grouping parenthesis AFTER an operator, when
you really meant to place the parenthesis BEFORE the operator, e.g., you
probably want this
(foo|bar)+ and NOT this
The first pattern matches the words ‘foo’ or ‘bar’ any number of
times, e.g., it matches the text ‘barfoofoobarfoo’. The
second pattern matches a single instance of
foo or a single instance of
bar followed by one or more ‘r’s, e.g., it matches the text
- A ‘.’ inside ‘’’s just means a literal‘.’ (period),
and NOT “any character except newline”.
- Remember that ‘.’ matches any character EXCEPT ‘\n’ (and ‘EOF’).
If you really want to match ANY character, including newlines, then use
Beware that the regex
(.|\n)+ will match your entire input!
- Finally, if you want to match a literal ‘.’ (a period), then use ‘[.]’ or ‘"."’