problem with re

Patrick Vrijlandt p.vrijlandt at aig.azn.nl
Thu Sep 6 13:14:35 EDT 2001


Hi,

I do not understand why the 7th regular expression does not give the same
result as 2-6.

(This is simplified from something I'm working on. The answer may be
trivial, but I don't see it)

TIA,
Patrick Vrijlandt

import re

data = """1234567890
abcdefghij
1234567890"""

def mymatch(pattern):
    mo = re.match(pattern, data)
    print mo,
    try:
        print mo.groups()
    except AttributeError:
        print


mymatch('.*\\n.*\\n.*')
mymatch('(.*)\\n(.*)\\n(.*)')
mymatch('(.{10})\\n(.{10})\\n(.{10})')
mymatch('(\d{10})\\n([a-z]{10})\\n(\d{10})')
mymatch(r'(\d{10})\n([a-z]{10})\n(\d{10})')
mymatch(r'\n'.join([r'(\d{10})', r'([a-z]{10})', r'(\d{10})']))
mymatch(r'\n'.join([r'(\d{10})|([a-z]{10})', r'([a-z]{10})', r'(\d{10})']))

<SRE_Match object at 015289E0> ()
<SRE_Match object at 0152DD10> ('1234567890', 'abcdefghij', '1234567890')
<SRE_Match object at 0152DD10> ('1234567890', 'abcdefghij', '1234567890')
<SRE_Match object at 0152DD10> ('1234567890', 'abcdefghij', '1234567890')
<SRE_Match object at 0152DD10> ('1234567890', 'abcdefghij', '1234567890')
<SRE_Match object at 0152DD10> ('1234567890', 'abcdefghij', '1234567890')
<SRE_Match object at 0152DD10> ('1234567890', None, None, None)









More information about the Python-list mailing list