python - 当两者都存在时,如何返回较小的 OR 运算符正则表达式?
问题描述
这个正则表达式:
import re
string = 'I am a long string with many regexes matching'
pattern = '.*(?:with|regexes)'
print(re.findall(pattern, string))
返回
['I am a long string with many regexes']
我怎样才能让它返回:
['I am a long string with']
即当正则表达式的短版本和长版本都存在时,返回较短的字符串。
解决方案
推荐阅读
- python - Python:如何查找和替换输入?
- java - org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy 找不到 WAR 工件的 appInfo
- java - spring kafka - 手动设置消费者日志级别(spring 5)
- python - 点击 QFrame 触发函数
- java - Android:调试 WebView.clearCache(boolean)
- java - 在 Android 中将 HTML 或 XML 转换为图像(RN Native Modules)
- r - 使用 if 或 ifelse 和 grepl 标记数据框
- python - 当服务器返回请求错误时我的代码挂起
- sql - 删除 SQL Server 上的重复记录
- reactjs - 带有 localStorage 的索引签名