Regex problem with multiline matches

Randall Hopper aa8vb at
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'.

 |>>> 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

More information about the Python-list mailing list