regexp strangeness
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri Apr 10 22:12:02 EDT 2009
On Thu, 09 Apr 2009 20:48:11 +0100, Dale Amon wrote:
> This finds nothing:
...
> DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!);\\\]%_>?]")
> This works correctly:
...
> DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!)\\;\]%_>?]")
> They differ only in the positioning of the quoted backslash.
So you're telling us that two different regexs do different things? Gosh.
Thanks for the heads up!
BTW, when creating regexes, you may find it much easier if you use raw
strings to avoid needing to escape backslashes:
'\n' in a string is a newline escape. To get a literal backslash followed
by an n, you can write '\\n' or r'\n'.
--
Steven
More information about the Python-list
mailing list