[Tutor] Why doesn't this regex match???
Sat, 09 Feb 2002 11:38:19 -0800
On Sat, 9 Feb 2002 09:43:31 -0500, Rick Pasotto <email@example.com> wrote
about Re: [Tutor] Why doesn't this regex match???:
> 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.
> 'word boundary' includes 'white space before and after' and 'beginning
> and end of string'.
p=re.compile(r'\b%s\b' % word, re.I)
didn't do what I wanted. That's what started this whole thread.
p = re.compile(r'(\A|\s)(%s)(\Z|\s)' % re.escape(word), re.I)
would do what I wanted. (untested)
Anyhow, after the discussion here on the list last night, and some
discussion with my project-code-partners, we've decided to forgo the
regular expressions in favor of simple string manipulations.
"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_