0

I need to do something like this:

st = 'abcdef'
wr = 'ab'

if re.search(^wr,st):    
    print 'OK'

the problem is I cannot combine special character with a variable (i.e. ^wr). Is there a way to do that?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
user3468837
  • 47
  • 1
  • 4
  • Maybe all you need is `if re.match(wr,st):` since you want to match at the start of the string only? – Wiktor Stribiżew Apr 15 '17 at 19:03
  • Note that you want to combine the character with the **value** of the variable, not with the name of the variable. You can do this with the `+` operator which concatenates two string values. – Code-Apprentice Apr 15 '17 at 19:06

0 Answers0