[Tutor] Why doesn't this regex match???

Rick Pasotto rick@niof.net
Sat, 9 Feb 2002 09:43:31 -0500


On Fri, Feb 08, 2002 at 11:26:53PM -0800, Sheila King wrote:
> 
> So I tried the following, with the dismal results shown. Now what am I
> doing wrong? 
> 
> >>> searchstring = 'ADV: FREE FREE OFFERZ!!!!'
> >>> word = 'adv:'
> >>> p = re.compile(r'[\b\A\s]%s[\b\Z\s]' % word, re.I)

'[]' says 'any one *character* from the set'. '\b', '\A', and '\Z' are
not characters.

p=re.compile(r'\b%s\b' % word, re.I) ought to do what you want.
(untested)

'word boundary' includes 'white space before and after' and 'beginning
and end of string'.

-- 
"Once the principle of government -- judicial monopoly and the power
 to tax -- is incorrectly accepted as just, any notion of restraining
 government power and safeguarding individual liberty and property is
 illusory." -- Hans-Herman Hoppe
    Rick Pasotto    rickp@telocity.com    http://www.niof.net