I found a similar question here . However, I did not get the job:
I have a string like "my_token_string" and you need a regular expression to return the tokens "my_", "_token_" and "_string".
Please note that I cannot change java code because it is part of other software. The only thing I can do is to specify the template and group to capture :-)
This is what I 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 only returns the _token_ and _string tokens.
source share