如何在 sublime 中搜索包含 2 个(或更多)特定单词的行?
How to search for lines with 2 (or more) specific words in sublime?
我想搜索包含 2 个(或更多)特定单词的行。例如,我在项目中多次出现 my function
:
my_function('test', 'test2')
my_function('test3', 'test4')
my_function(nil, 'test5')
等等
我只想查找包含 nil
.
的那些事件
有什么方法可以使用 Sublime 的 Find in files
?
先按 ctrl+shift+f 然后输入 find 和 where 以及下面的查询
Find: (string1|string2)
Where: <path of the folder>
打开Find in files
并启用正则表达式(Alt+R快捷方式)。
然后使用此正则表达式查找出现的事件 my_function\((.*)?nil(.*)?\)
此 RegEx 模式使您可以高度控制函数中允许使用的字符:
my_function\([a-zA-Z0-9,-_'"\s]*?nil[a-zA-Z0-9,-_'"\s]*?\)
或者,如果您想要一个更简单的匹配来查找包含 my_function
后跟 nil
的任何行,请使用:
my_function.*nil
或以任何顺序匹配包含 my_function
和 nil
的任何行,使用:
(my_function.*nil)|(nil.*my_function)
细分:
[1] my_function\(
[2] [a-zA-Z0-9,-_'"\s]*?
[3] nil
[4] [a-zA-Z0-9,-_'"\s]*?
[5] \)
第 1 组和第 5 组包含转义括号。
第 2 组和第 4 组包含匹配的字符集:
所有字母数字字符、逗号、下划线、单引号、双引号和空格
更多信息@:
Live Demo
我想搜索包含 2 个(或更多)特定单词的行。例如,我在项目中多次出现 my function
:
my_function('test', 'test2')
my_function('test3', 'test4')
my_function(nil, 'test5')
等等
我只想查找包含 nil
.
有什么方法可以使用 Sublime 的 Find in files
?
先按 ctrl+shift+f 然后输入 find 和 where 以及下面的查询
Find: (string1|string2)
Where: <path of the folder>
打开Find in files
并启用正则表达式(Alt+R快捷方式)。
然后使用此正则表达式查找出现的事件 my_function\((.*)?nil(.*)?\)
此 RegEx 模式使您可以高度控制函数中允许使用的字符:
my_function\([a-zA-Z0-9,-_'"\s]*?nil[a-zA-Z0-9,-_'"\s]*?\)
或者,如果您想要一个更简单的匹配来查找包含 my_function
后跟 nil
的任何行,请使用:
my_function.*nil
或以任何顺序匹配包含 my_function
和 nil
的任何行,使用:
(my_function.*nil)|(nil.*my_function)
细分:
[1] my_function\(
[2] [a-zA-Z0-9,-_'"\s]*?
[3] nil
[4] [a-zA-Z0-9,-_'"\s]*?
[5] \)
第 1 组和第 5 组包含转义括号。
第 2 组和第 4 组包含匹配的字符集:
所有字母数字字符、逗号、下划线、单引号、双引号和空格
更多信息@: