python - 正则表达式python匹配单词与`est`
问题描述
嗨,我正在尝试匹配包含est
句子中的单词。
例如字符串是:
You are the best
greatest show of all time
我想要的输出是
best
greatest
到目前为止,这是我的正则表达式代码
(?:^|)(est|est)(?:$|)
关于如何实施它的任何想法?
解决方案
我会re.findall
用这种模式\b\w*est\w*\b
:
inp = """You are the best
greatest show of all time"""
matches = re.findall(r'\b\w*est\w*\b', inp)
print(matches)
这打印:
['best', 'greatest']
正则表达式模式查找包含 g 的所有单词est
,允许在之前或之后的任意数量的单词字符est
。
推荐阅读
- oracle - 创建在不同表中的列更新时更新表的触发器
- arrays - AutoIT 将 1d 和 2d 数组中的元素相加
- javascript - 如何使代码与其他标签一起使用并为其添加类?
- javascript - 如何使用反应钩子动态添加“refs”?
- javascript - 正确使用 removeChild()
- python - 如何使用按钮关闭正在运行的 Windows 操作系统程序?
- javascript - 如何从当前窗口选项卡数组中将状态设置为活动选项卡?
- php - 在 Laravel 5.5 中增加多次失败登录尝试的时间
- python - curve_fit 中的多个变量,sigma 的形状不正确?
- python - 如何从 numpy 数组中获取列而不是列表?