python - 如何在python中使用正则表达式-re.findall查找大写和小写
问题描述
我有一个搜索表达式并突出显示匹配单词的代码。
无论是大写还是小写,我都需要找到匹配项,我需要搜索以忽略区分大小写。
代码:
RepX='<u><b style="color:#FF0000">'+x+'</b></u>'
for counter , myLine in enumerate(filename):
#added
self.textEdit_PDFpreview.clear()
thematch=re.sub(x,RepX,TextString)
thematchFilt=re.findall(x,TextString,re.M|re.IGNORECASE)
例如搜索词:charles
现有的词是查尔斯
除非我写了Charles,否则系统将找不到搜索的单词。
解决方案
import re
text = "234422424"
text2 = "My text"
print( re.findall( r'^[A-Öa-ö\s]+', text)) # []
print( re.findall( r'^[A-Öa-ö\s]+', text2)) # ['My text']
推荐阅读
- c - 如何正确引用 C 中的两个结构?
- javascript - 以一定的质量初始化 dash.js
- javascript - 如何在 Internet Explorer 中下载时显示对话框,如 FireFox 所示?
- asp.net - 使用 DataGrid 上的更新/删除命令更新会话数组列表
- debugging - 如何在谷歌操作日志中获取堆栈跟踪,因为必须设置“final_response”是无用的
- javascript - Symfony 中的日期范围过滤器使用 fosjsrouting Bundle
- assembly - 如何在 PIC24F 汇编代码中实现循环
- sql-server - 如何在动态sql中使用表变量?或者从用户定义的表类型创建临时表?
- javascript - 在另一个文本框或 div 中写入内容后清除一个文本框或 div
- field - 在主题中显示自定义字段 (processwire)