java
Pattern p = Pattern.compile("(?=hopeful)hope"); String str = "hopeful"; Matcher m = p.matcher(str); while(m.find()){ System.out.println(m.group()); }
Whether the hopeful can be matched and, if so, captures the hope in hopeful.
Of course continue to look backwards for matching substrings, starting with F. The comparison can be seen, (=hopeful) Hope and Hope (? =ful), two regular effect is actually the same
Although see the above explanation still can't understand, saw Hope (? =ful) This writing, another kind of writing how to understand? I always thought (? =) is used to match whether or not to end this form of xxx ...
Reply content:
java
Pattern p = Pattern.compile("(?=hopeful)hope"); String str = "hopeful"; Matcher m = p.matcher(str); while(m.find()){ System.out.println(m.group()); }
Whether the hopeful can be matched and, if so, captures the hope in hopeful.
Of course continue to look backwards for matching substrings, starting with F. The comparison can be seen, (=hopeful) Hope and Hope (? =ful), two regular effect is actually the same
Although see the above explanation still can't understand, saw Hope (? =ful) This writing, another kind of writing how to understand? I always thought (? =) is used to match whether or not to end this form of xxx ...
(? =exp) matches the position of the exp front
(?=hopeful)hope
(? =hopeful) + Hope
(? =hopeful) positioning is the index of H in hopeful to match, then found the hope
hope(?=ful)
Hope + (? =ful)
First find hope after the match ful index can try hope(?=ful)ful
to matchhopeful
You can assume that the match is to move the cursor to the beginning of the matched text in the text editor and check the capture text.
Hope matching effect is |hope... The vertical bar represents the cursor position, and the next match starts after E.
(? ful) matches the ful, but the capture length is 0, the effect is equal to ... | Ful
The combination of both matches the entire hopeful but captures only hope
The (? hopeful) match effect is |hopeful, matching the entire hopeful, and the next match still starts with H
Subsequent hope matching effect is |hope...
The effect is the same as the above regular.