java - Overlapping regular expression -
I got a similar question though I did not find the job:
I like "my_token_string" There is a string and a regex is needed to return the token "my_", "_token_", and "_string".
Please note that I can not change the Java code as it is part of any other software. The only thing I can do is to capture patterns and groups: -)
This is what I have done:
string p = " (? = (_ [^ _] * _))? "; Int group = 1; String test = "my_token_string"; Matcher m = Pattern.compile (p). Mishor (test); While (m.find ()) {System.out.println (m.group (group)); } But of course it only gives "_token_" and "_string" token.
you "(? = ((| | | _).? (_ | $) ). Try using " as the group number 1 . This will start with _ or input ( Will start the token with ^ ) and end it with _ or end up with input ( $ ) instead of < Code> [^ _] + , but I like this version.
Comments
Post a Comment