Skip to main content
 首页 » 编程设计

python之它在 awk 中可能更简单,但我怎么能在 Python 中这样说呢

2025年05月04日16soundcode

我有:

Rutsch 适合 rutterman 斜坡

这是《芬尼根守灵夜》中的一句话。这本史诗般的谜语书充满了这样的主旋律,例如“脱掉那顶白帽子”和“小费”,所有这些都会根据您在书中的位置而变异为发音相似的词。我想要的只是一种方法来找到这个特定主题的明显出现,IE

[word1] 用于 [word2] [word-part1]ing his [word3]

请您参考如下方法:

您可以在 Python 中使用正则表达式来做到这一点:

import re 
pattern = re.compile(r'(?P<word>.*) is for (?P=word) (?P=word)ing his (?P=word)') 
words = pattern.findall(text) 

这不会匹配您的示例,但会匹配[word] is for [word] [word-part]ing his [word]。加入调味料调味。您可以在 re 模块中找到更多详细信息 docs .