[Tutor] Why doesn't this regex match???
Sheila King
sheila@thinkspot.net
Sat, 09 Feb 2002 11:38:19 -0800
On Sat, 9 Feb 2002 09:43:31 -0500, Rick Pasotto <rick@niof.net> 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.
> (untested)
>
> 'word boundary' includes 'white space before and after' and 'beginning
> and end of string'.
Actually,
p=re.compile(r'\b%s\b' % word, re.I)
didn't do what I wanted. That's what started this whole thread.
Maybe
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.
--
Sheila King
http://www.thinkspot.net/sheila/
"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_