I'm using Python3 and trying to use regular expression match a pattern to a value in a variable. Before posting, I looked at:
How to use variables in Python regular expression
--and--
How to use a variable inside a regular expression?
Here's the code:
import re
x = []
x.append("test")
x.append("me")
x.append(x[0] + x[1])
TEXTO = x[2]
print(TEXTO)
if re.search(rf"\b(?=\w){TEXTO}\b(?!\w)", "StM", re.IGNORECASE):
print("Successful match")
else:
print("Match attempt failed")
if re.search('(.+)'+TEXTO+'(.+)', "StM", re.IGNORECASE):
print("Successful match")
else:
print("Match attempt failed")
and it's still failing. Both outputs received are "Match attempt failed"
[dogzilla@localhost ~]$ python3 py1.py
testme
Match attempt failed
Match attempt failed
What is the proper way to put the variable in question (TEXTO) in the search method?
Thanks!