About Python Re Raw Pattern Search
I want to perform re.search using the pattern as a raw string like below. m=re.search(r'pattern',string) But if I have the 'pattern' in variable like pat='pattern'. How do I perfo
Solution 1:
You declare the pattern string as a raw string:
regexpattern = r'pattern'
m=re.search(regexpattern,string)
Solution 2:
you can give the raw input this way. test is the string variable.
pat = """pat%s""" % test
pattern = re.compile(pat, re.I | re.M)
match = pattern.search(l)
Post a Comment for "About Python Re Raw Pattern Search"