如何使用regex查找大写和小写关于芬德尔在python中

2024-07-08 16:32:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个搜索表达式并突出显示匹配单词的代码。你知道吗

我需要找到匹配无论其大小写我需要搜索忽略大小写敏感。你知道吗

代码:

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

除非我写下Charles,否则系统将找不到搜索到的单词。你知道吗


Tags: 代码inrefor表达式stylecounter单词
3条回答

^{}将参数作为re.findall(pattern, string, flags=0)。你知道吗

import re
s = 'the existing word is Charles'
print(re.findall(r'charles', s, re.IGNORECASE))
# ['Charles']

^{}确保不区分大小写的匹配。你知道吗

问题出在thematch=re.sub(x,RepX,TextString)它还需要参数标志。 所以它变成thematch=re.sub(x,RepX,TextString,flags= re.M|re.I)

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']

相关问题 更多 >

    热门问题