For example,I have a variable A, I want to match it 1-3times in a string B. How to implement this? Just like a feeling that re.search(A{1,3},B)
IIUC, this is what you're looking for
import re
test_var = 'test'
test_str = 'bleeptesttestbloop'
test_regex = re.compile('.*' + test_var + '{1,3}.*')
re.match(test_regex, test_str)
The best advice for working with regex is to use a regex testing website like https://regexr.com/ or https://rubular.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.