[Tutor] Variables in regular expressions

alan.gauld@bt.com alan.gauld@bt.com
Mon, 26 Mar 2001 12:05:12 +0100


> >>> import re
> >>> matchstr = 'fleas'
> >>> sentence = 'my dog has fleas'
> >>> if re.match(matchstr, sentence): print "Yes, it works."
> ...

try re.search()

match() only matches if 'fleas' is at the start of the line.

Alan G