我有一个代码,可以搜索表达式并突出显示匹配的单词。
我需要找到匹配项,无论它是大写还是小写,我需要搜索忽略区分大小写。
法典:
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)
搜索单词示例:查尔斯
现存的词是查尔斯
除非我写查尔斯,否则系统将无法找到搜索到的单词。
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']
re.findall
将参数作为re.findall(pattern, string, flags=0)
。
import re
s = 'the existing word is Charles'
print(re.findall(r'charles', s, re.IGNORECASE))
# ['Charles']
re.IGNORECASE
可确保不区分大小写的匹配。
问题出在thematch=re.sub(x,RepX,TextString)
它还需要参数标志。 所以它变得thematch=re.sub(x,RepX,TextString,flags= re.M|re.I)