a re question

Rajarshi Guha rajarshi at presidency.com
Mon Sep 9 16:31:08 EDT 2002


On Mon, 09 Sep 2002 16:10:39 -0400, Rajarshi Guha wrote:

> Hi,
>   I have a file with lines of the format:
> 
> 001 Abc D Efg 123456789   7 100 09/05/2002 20:23:23 001 Xya FGh
> 143557789   7 100 09/05/2002 20:23:23
> 
> I am trying to extract the 9 digit field and the single digit field
> immediatley after that.
> 
> When I use Visual Regexp to try out the regexp
> 
> (\d{9,} {3,}\d)
> 
> it highlights the 2 fields exactly.
> 
> But when I use the following Python code I get None:
> 
>>> s='001 Abc D Efg 123456789   7 100 09/05/2002 20:23:23' p =
>>> re.compile(r'(\d{9,} {3,}\d)')
>>> print p.match(s)
>>> None

OK - I got it working using p.split() rather than p.match()
Why does'nt p.match() the line but p.split() is able to split it using
the same regex?



More information about the Python-list mailing list