问题描述:

I would like to search for lines which contains 2 (or more) specific words. For example I have multiple occurrences of my function in project:

my_function('test', 'test2')

my_function('test3', 'test4')

my_function(nil, 'test5')

etc.

I would like to look only for those occurrences which contains nil.

Any way of doing that using Sublime's Find in files?

网友答案:

This RegEx pattern gives you a high degree of control over what characters are allowed within the function:

my_function\([a-zA-Z0-9,-_'"\s]*?nil[a-zA-Z0-9,-_'"\s]*?\)

Alternatively, if you want a simpler match that finds any line which contains my_function followed by nil, use:

my_function.*nil

Or to match any line which contains both my_function & nil, in any order, use:

(my_function.*nil)|(nil.*my_function)



Breakdown:

    [1]     my_function\(
    [2]     [a-zA-Z0-9,-_'"\s]*?
    [3]     nil
    [4]     [a-zA-Z0-9,-_'"\s]*?
    [5]     \)

Groups 1 & 5 contain escaped parentheses.

Groups 2 & 4 contain a character set that matches:
all alphanumeric characters, commas, underscores, single quotes, double quotes, & whitespace



More info @:

Live Demo

网友答案:

first press ctrl+shift+f then type in find and where with below query

Find: (string1|string2)
Where: <path of the folder>
网友答案:

Open Find in files and enable Regular expressions (Alt+R shortcut).

Then use this regex to find the occurences my_function\((.*)?nil(.*)?\)

相关阅读:
Top