[regex-coach] problem with dot '.' inside brackets
Edi Weitz
edi at agharta.de
Wed Apr 26 21:17:25 UTC 2006
On Wed, 26 Apr 2006 12:44:30 -0700, sites at brynmosher.com wrote:
> I've been using Regex-Coach 0.8.4 on Windows to test some
> SpamAssassin rules and noticed something odd:
>
> Placing the following expression:
> [.|m]
>
> to match the following data:
> bleh.com
>
> Matches the '.' in bleh.com and not the first non-linefeed character
> as the '.' character in the expression should match. It's almost as
> if I had excaped the '.' like '\.'. Using the expression '[.]'
> yields the same result. I've also noticed that the non-match
> character '^' doesn't work inside brackets as well.
>
> Is this an error or am I crazy?
Well, at least it's not an error... :)
Most characters that have a special meaning in regular expressions
(like the dot or the pipe symbol, for example) are treated like normal
characters within character classes, i.e. within square brackets.
See 'man perlre' for details.
BTW, it seems that your understanding of character classes as a whole
is wrong. If the dot /would/ match every non-linefeed character, then
"[.|m]" would be equivalent to "[.]".
Cheers,
Edi.
More information about the regex-coach
mailing list