How to use a variable inside a regular expression?

后端 未结 10 1881
青春惊慌失措
青春惊慌失措 2020-11-22 03:29

I\'d like to use a variable inside a regex, how can I do this in Python?

TEXTO = sys.argv[1]

if re.search(r\"\\b(?=\\         


        
10条回答
  •  心在旅途
    2020-11-22 03:41

    you can try another usage using format grammer suger:

    re_genre = r'{}'.format(your_variable)
    regex_pattern = re.compile(re_genre)  
    

提交回复
热议问题