regexpr. and metachars

Terry Reedy tjreedy at udel.edu
Wed Nov 1 18:25:37 EST 2000


"> i seem to have overcome my problem by using different regexp. syntax:
>
> re.compile(r'\\W{') will match the string "\W{"

raw string passes to re as is, and re collapses \\ to \.

> re.compile('\\W{') will fail to match the string "\W"

Python (underlying C string handler) collapses \\ to \.  Re then collapses
\W to the corresponding
internal token (NONWORD or whatever).
>
> why??

One \ interpretation versus two.






More information about the Python-list mailing list