[英]How to match a variable in PYTHON regular expression [on hold]
例如,我有一個變量 A,我想在字符串 B 中匹配它 1-3 次。如何實現呢? 就像re.search(A{1,3},B)的感覺
IIUC,這就是你要找的
import re
test_var = 'test'
test_str = 'bleeptesttestbloop'
test_regex = re.compile('.*' + test_var + '{1,3}.*')
re.match(test_regex, test_str)
使用正則表達式的最佳建議是使用正則表達式測試網站,例如https://regexr.com/或https://rubular.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.