Regex 如何";查找代码中同时包含A和B的文件;使用注释++;?
我发现Notes++的“在文件中查找”对于理解一个有点复杂的程序来说是一件很好的事情 但是,我试图在代码中找到同时包含A和B的py文件(在某些特定目录中)Regex 如何";查找代码中同时包含A和B的文件;使用注释++;?,regex,notepad++,Regex,Notepad++,我发现Notes++的“在文件中查找”对于理解一个有点复杂的程序来说是一件很好的事情 但是,我试图在代码中找到同时包含A和B的py文件(在某些特定目录中) 我想我必须使用正则表达式,但我自己无法做到。未经测试,但我可以想象这样的方法可以工作(同时消耗大量内存): 您需要确保检查。匹配换行符复选框。此项的常规正则表达式为: ^(?s)(?=.*A).*B.* (将A和B替换为您要查找的任何表达式或文字。) 这与文件的整个内容相匹配 解释正则表达式 ^
我想我必须使用正则表达式,但我自己无法做到。未经测试,但我可以想象这样的方法可以工作(同时消耗大量内存):
您需要确保检查
。匹配换行符
复选框。此项的常规正则表达式为:
^(?s)(?=.*A).*B.*
(将A和B替换为您要查找的任何表达式或文字。)
这与文件的整个内容相匹配
解释正则表达式
^ # the beginning of the string
(?s) # set flags for this block (with . matching
# \n) (case-sensitive) (with ^ and $
# matching normally) (matching whitespace
# and # normally)
(?= # look ahead to see if there is:
.* # any character (0 or more times (matching
# the most amount possible))
A # 'A'
) # end of look-ahead
.* # any character (0 or more times (matching
# the most amount possible))
B # 'B'
.* # any character (0 or more times (matching
# the most amount possible))
这似乎有效!非常感谢。
^ # the beginning of the string
(?s) # set flags for this block (with . matching
# \n) (case-sensitive) (with ^ and $
# matching normally) (matching whitespace
# and # normally)
(?= # look ahead to see if there is:
.* # any character (0 or more times (matching
# the most amount possible))
A # 'A'
) # end of look-ahead
.* # any character (0 or more times (matching
# the most amount possible))
B # 'B'
.* # any character (0 or more times (matching
# the most amount possible))