[Tutor] RE match on a file

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Feb 17 18:06:01 2003


On Mon, 17 Feb 2003, Bob Hicks wrote:

> I am trying to do a regular expression match on:
>
> 20030214-001-x86.exe
>
> r'\d{8}.*x86\.exe' does not seem to do it.

Hi Bob,


Can you explain why you think the above pattern doesn't work? I just want
to make sure we're on the same page.  *grin*

The reason we need to ask this is because r'\d{8}.*x86.exe' does appear to
recognise your sample string:

###
>>> pattern = re.compile(r'\d{8}.*x86\.exe')
>>> pattern.match('20030214-001-x86.exe')
<_sre.SRE_Match object at 0x816f360>
###

So that matches.


In general, whenever we're debugging, we need some test case to verify the
problem.  Your example doesn't exhibit the problem you're looking for, so
we can't do much without reading your mind, or guessing.  *grin*

Show us a counterexample that shows where the regular expression either is
too overzealous or too lenient, and we can work from there.  Talk to you
later!