我正在尝试新的正则表达式模块的模糊功能。在这种情况下,我希望找到所有具有 <= 1 错误的字符串的匹配项,但我遇到了麻烦
import regex
statement = 'eol the dark elf'
test_1 = 'the dark'
test_2 = 'the darc'
test_3 = 'the black'
print regex.search('{}'.format(test_1),statement).group(0) #works
>>> 'the dark'
print regex.search('{}'.format(test_1){e<=1},statement).group(0)
>>> print regex.search('{}'.format(test_1){e<=1},statement).group(0) #doesn't work
^
SyntaxError: invalid syntax
我也试过
print regex.search('(?:drk){e<=1}',statement).group(0) #works
>>> 'dark'
但是这个 。. .
print regex.search(('(?:{}){e<=1}'.format(test_1)),statement).group(0) #doesn't work
>>> SyntaxError: invalid syntax