Answers for "variable in regex python"

1

variable in regex python

import re
s = 'I love books'
var_name = 'love'
result = re.search('(.+)'+var_name+'(.+)',s)
print result
var_name = 'hate'
s2 = 'I hate books'
result = re.search('(.+)'+var_name+'(.+)',s2)
print result
Posted by: Guest on August-20-2020

Python Answers by Framework

Browse Popular Code Answers by Language