I want to get a portion of string that contains one of the targeted words. For example, from the following example string:
...
def a:
...
target1
...
def b:
...
def c:
...
I want to get this part:
def a:
...
target1
...
Here is my Java code:
s = "(def\\W(.*)\\W(target1|target2|target3)\\W(.*)def\\W)";
Pattern p = Pattern.compile(s);
Matcher m = p.matcher(sourceString);
while(m.find()){
System.out.println(m.group(0));
}
The problem is that it does not find out anything.
Thanks so much for your help!