In recent development work, I often needed to find specific multiple-lines texts (*) by searching the code base. Note: Those multiple-lines texts are often back-end methods or front-end tags.
In the following case, to find methods which name is like doSomethingXxx
, I use the regular expression public void doSomething.+\(\) \{[\s\S]+?\}
, and it works well (getting the 3 matches).
But furthermore, when I needed to find specific multiple-lines texts including/excluding some string, in the following case, find methods which name is like doSomethingXxx
but includes/excludes the string 456
, I have no solution by far.
When finding methods including the string 456
, the regular expression should return 1 match - the method doSomething2
; When finding methods excluding the string 456
, the regular expression should return 2 matches - the methods doSomething1
and doSomething3
.
Here are some failed regular expressions I have tested: public void doSomething.+\(\) \{[\s\S]+?456[\s\S]+?\}
(returns 1 match containing both the methods doSomething1
and doSomething2
), public void doSomething.+\(\) \{[\s\S]+?(456){0}[\s\S]+?\}
(returns 3 matches which are the methods doSomething1
, doSomething2
and doSomething3
respectively).
Could you help find one solution? Thanks very much.
...
public void doSomething1() {
// XXXXX
// 123
// XXXXX
}
...
public void doSomething2() {
// XXXXX
// 456
// XXXXX
}
...
public void doSomething3() {
// XXXXX
// 789
// XXXXX
}
...