470,591 Members | 2,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Variable in Regex

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?
Jul 18 '05 #1
2 8350
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)
Jul 18 '05 #2
Christian von Essen <ch*******@mvonessen.de> wrote in message news:<c4**********@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!
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tim Conner | last post: by
4 posts views Thread by Jozef Jarosciak | last post: by
20 posts views Thread by jeevankodali | last post: by
10 posts views Thread by Mason Barge | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.