复杂模式下的python正则表达式搜索

复杂模式下的python正则表达式搜索,python,regex,escaping,Python,Regex,Escaping,我对python不太了解 这对我来说很难 现在我在文件中找到一些字符串 我有正则表达式,但我不知道如何在python中使用它。它在Eclipse中工作 下面是正则表达式 ("|')\w+\1\s*=\s*?\w*?\.?suppkdid 这是我的来源,我试过了 import fnmatch, re, os regex = '' #Q1. How could it be possible? for root, dirnames, filenames in os.walk('C:\the

我对python不太了解

这对我来说很难

现在我在文件中找到一些字符串

我有正则表达式,但我不知道如何在python中使用它。它在Eclipse中工作

下面是正则表达式

("|')\w+\1\s*=\s*?\w*?\.?suppkdid
这是我的来源,我试过了

import fnmatch, re, os

regex =  ''  #Q1. How could it be possible? 

for root, dirnames, filenames in os.walk('C:\the_file_directory'):
    for filename in fnmatch.filter(filenames, '*.odi'):
        with open(os.path.join(root, filename)) as f:
            for line in f:
                                if regex.search(line) is not None: #Q2. Is it right?
                                    print '=========================='
                                    print 'filename : %s' %filename 
                                    print 'line : %s' %line
                                    print '=========================='
您需要创建一个正则表达式编译模式

事实上你可以直接使用

if re.search(r"""("|')\w+\1\s*=\s*?\w*?\.?suppkdid""",line) is not None:
也使用

""" 

不要使用
,因为它们都在您的模式中。

Ookay,我将尝试新的一个。我需要更多,如何使用此正则表达式不区分大小写?@lv0gun9只需添加
flag=re.Ignorecase
"""