Variable in Regex

J Hamilton tyrone_1066 at yahoo.com
Sun Mar 28 03:15:13 EST 2004


Christian von Essen <christian at mvonessen.de> wrote in message news:<c44r1e$nat$1 at online.de>...
> 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)

I don't know what I was doing wrong, but it works now.

Thanks for the help!



More information about the Python-list mailing list