即時嘗試新的正則表達式模塊的模糊功能。在這種情況下,我希望在那裏找到與< = 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
你把字符串正在搜索? –