By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,537 Members | 1,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,537 IT Pros & Developers. It's quick & easy.

Variable in Regex

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.