Variable in Regex

Christian von Essen christian at mvonessen.de
Sat Mar 27 16:17:34 EST 2004


J Hamilton wrote:
> In Perl in can put a scalar variable in a regex as the pattern.
> 
> for example: m/$var/  where $var contains the string I want to match
> 
> Is there a way to do this in Python?

For example:
re.search("%s" % var, StrinToMatch)
or even simpler:
re.search(var, StringToMatch)



More information about the Python-list mailing list