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

alan.gauld@bt.com alan.gauld@bt.com
Sun Nov 17 12:10:04 2002


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

re.search takes a regular expression string as its first parameter, 
you are passing a reglar expression bject. You should be able to do 
either of:

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

OR

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

The latter is easier to understand if written on two lines like:

REobj = re.compile ("(.)\b(.)")
REobj.search("spam and eggs are yummy")

HTH,

Alan G.