[Tutor] RE expressions

Steve Willoughby steve at alchemy.com
Sat Aug 16 00:01:46 CEST 2008


Steve Willoughby wrote:
> Johan Nilsson wrote:
>> In [74]: p.findall('asdsa"123abc\123"jggfds')
>> Out[74]: ['"123abcS"']

By the way, you're confusing the use of \ in strings in general with the 
use of \ in regular expressions and the appearance of \ as a character 
in data strings encountered by your Python program.

When you write the code:

p.findall('asdsa"123abc\123"jggfds')

the character string 'asdsa"123abc\123"jggfds' contains the special code 
\123 which means "the ASCII character with the octal value 123".  That 
happens to be the letter S.  So that's the same as if you had typed:

p.findall('asdsa"123abcS"jggfds')

which may explain your results.

using a raw string would have solved that problem.


More information about the Tutor mailing list