gpt4 book ai didi

Python使用子字符串在字符串中查找字符串

转载 作者:太空宇宙 更新时间:2023-11-04 09:45:39 25 4
gpt4 key购买 nike

<分区>

我需要在包含子字符串的字符串中找到整个单词。

例如,如果 replacement 是一个字符串,我将搜索 replace ,那么它将匹配 replacement 并且它应该返回 replacement。

这是我尝试过的

>>> a = 'replacement replace  filereplace   filereplacer'
>>> re.findall(r'replace',a)

['replace', 'replace', 'replace', 'replace']

但我需要的是:

['replacement', 'replace', 'filereplace', 'filereplacer']

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com