[Tutor] Regular expressions - Ignoring linefeeds
kent37 at tds.net
Fri Mar 2 20:16:54 CET 2007
Luke Paireepinart wrote:
> doug shawhan wrote:
>> I've been looking through various sites, but cannot find the magic
>> button that allows me to match a string with linefeeds
>> I'd rather not strip out the linefeeds, then stick them back in. :-)
>> I'm attempting something that should be fairly simple:
>> snippy = re.compile('Hi there.*Bye there.')
> Your RE is wrong.
> Refer to http://docs.python.org/lib/re-syntax.html
> * Causes the resulting RE to match 0 or more repetitions of the
> preceding RE, as many repetitions as are possible. ab* will match 'a',
> 'ab', or 'a' followed by any number of 'b's.
The RE that is repeated is . which is the intent.
>> s = '''Good gravy! Hi there.
>> I'm some text someone
>> wants to match.
>> Bye there. See you around'''
>> yield = re.match (snippy)
> There are multiple errors in this call.
> First, yield is a reserved keyword in python 2.4+ (probably earlier, too.)
> Second, re.match takes 2 arguments, not 1.
> What you really want to do is re.match(snippy,s)
More information about the Tutor