[Tutor] Is it possible to load variable into a regex string?

Tom Tucker tktucker at gmail.com
Wed Apr 27 22:52:57 CEST 2005


Hello all! I am trying to pass a variable to my re.compile string (see
broken example below). Is something like this possible?  Thanks!

regexstring = 'H\sb'
textstring = 'BLAH blah'
match = re.compile((%s) % (regexstring))  # ?
if match.search(line):
          print "I found it!"


Tom


More information about the Tutor mailing list