How to put variable in regex pattern with Python

1 Answer

0 votes
import re

str = "c# python java c python c++"

var = "python"

r = re.findall(f"\s{var}", str)

print(r)




'''
run:

[' python', ' python']

'''

 



answered Jun 16, 2022 by avibootz
...