Unable to make regular expression match on multiline files

David Lees joeoptics at hotmail.com
Thu Nov 15 16:41:04 EST 2001


I am trying to use a simple regular expression to extract some digits
which are tagged with ascii text.  Everything works fine on a single
line, but when I use text that has the '\n' character it fails.  Here is
a sample.

Thanks in advance.

david lees


>>> p=re.compile('.*Number States: (\d+)',re.MULTILINE)
>>> a=' End: -1STATS:\nNumber States: 6\njunk'
>>> m=p.match(a)
>>> m.groups()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'None' object has no attribute 'groups'
-- 
debl



More information about the Python-list mailing list