Regex problem with multiline matches

Randall Hopper aa8vb at yahoo.com
Mon Nov 1 17:12:31 CET 1999


Skip Montanaro:
 |Randall Hopper:
 |    >>>> print re.compile( "b(.)", re.M ).match( "aa\nbb" )
 |    None
 |
 |The match method anchors the search at the beginning of the string.  Try the
 |search method instead:
 |
 |    >>> print re.compile( "b(.)", re.M ).search( "aa\nbb" )

Thanks.  I should have caught that in the docs.  'match' just didn't
register as really 'match_prefix' or 'match_at_beginning_of_line'.

Darrell:
 |Or
 |
 |>>> print re.compile( "(?s).*?b(.)").match( "aa\nbb" )

Hey that's slick!  Learn something new every day.  Just change the
interpretation of period so it can eat newlines too.

Thanks guys!

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list