即时尝试新的正则表达式模块的模糊功能。在这种情况下,我希望在那里找到与< = 1个错误的所有字符串匹配,但我无法与它新的正则表达式模块函数错误值。 Python
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
只有一个'('。应该是这样的:'print regex.search('(?:{}){e <= 1}'.format(test_1))。group(0)' – TobiMarg
你把字符串正在搜索? –