[Tutor] Re: Regexes -- \b ; re.sub

Emile van Sebille emile@fenx.com
Sat Nov 16 11:32:01 2002


John Abbe:
> Can someone explain to me why this...

Use raw strings to allow re to be passed the \'s.

>
> import re
> matches = re.search (re.compile ("(.)\b(.)"), "spam and eggs are
yummy")

try with :... r("(.)\b(.)"), ...


> if matches:
>     print matches.groups()
> else:
>     print "no match"
>
> ...prints out "no match", and this...
>
> print re.sub (re.compile ("(i)"), "o\1o", "i like eggs and spam")

try again with r"o\1o"

HTH,


--

Emile van Sebille
emile@fenx.com

---------