I found a similar question here. However I didn't get it working:
I have a string like "my_token_string" and need a regex to return the tokens "my_", "_token_", and "_string".
Please note that I am not able to change the java-code because it's part of another software. The only thing I can do is specify the pattern and the group to capture :-)
This is what I have tested:
String p = "(?=(_[^_]*_?))";
int group = 1;
String test = "my_token_string";
Matcher m = Pattern.compile(p).matcher(test);
while (m.find()) {
System.out.println(m.group(group));
}
But of course this returns only the tokens "_token_" and "_string".