I have a code that search for expressions and highlight the matching word .
我有一个代码搜索表达式并突出显示匹配的单词。
I need to find the match regardless if its upper or lower cases i need the search to ignore the case sensitive .
我需要找到匹配,无论其大写还是小写我需要搜索忽略区分大小写。
code:
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)
example the searched word : charles
例如搜索到的单词:charles
the existing word is Charles
现有的词是查尔斯
the system will not find the searched word unless i wrote Charles.
除非我写Charles,否则系统将找不到搜索到的单词。
3 个解决方案
#1
0
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']
#2
0
re.findall
takes parameters as re.findall(pattern, string, flags=0)
.
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
ensures a case-insensitive match.
re.IGNORECASE确保不区分大小写的匹配。
#3
0
The problem was in thematch=re.sub(x,RepX,TextString)
it need also parameter flags. so it becomes thematch=re.sub(x,RepX,TextString,flags= re.M|re.I)
问题出在thematch = re.sub(x,RepX,TextString)中,它还需要参数标志。所以它变成了thematch = re.sub(x,RepX,TextString,flags = re.M | re.I)
#1
0
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']
#2
0
re.findall
takes parameters as re.findall(pattern, string, flags=0)
.
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
ensures a case-insensitive match.
re.IGNORECASE确保不区分大小写的匹配。
#3
0
The problem was in thematch=re.sub(x,RepX,TextString)
it need also parameter flags. so it becomes thematch=re.sub(x,RepX,TextString,flags= re.M|re.I)
问题出在thematch = re.sub(x,RepX,TextString)中,它还需要参数标志。所以它变成了thematch = re.sub(x,RepX,TextString,flags = re.M | re.I)