我在使用python regex库(re)匹配特定模式时遇到了一些麻烦。我正在尝试用数字(最多3个数字)匹配行,然后匹配单词集合(第一个单词和数字之间没有空格),这些单词正好由两个空格终止。括号中包含匹配字符串的一些示例:
test(58your own becoming )Adapted from Pyramid Text utterance 81.
(46ancestral fires )In Sumerian, a language recently supplanted by
(45lap of God )Ginzberg, Legends of the Bible, p. 1.
(9Island of the Egg )The symbolism of the cosmic egg is an integral aspect of almost every mythological tradition. In the
我正在使用以下表达式:
(\d+).+( )
Run Code Online (Sandbox Code Playgroud)
相关的python代码如下:
# the search string is `tmp`
pattern = re.compile("(\d+).+( )")
footnotes = pattern.finditer(tmp)
for footnote in footnotes:
# do something with each match …Run Code Online (Sandbox Code Playgroud)