2013年10月11日星期五

This regular did not understand , who gave me explain ?


 i = 0;
 p = Pattern.compile("(fds){2,}");//(fds){2,}
 m = p.matcher("dsa da fdsfds aaafdsafds aaf");
 sb = new StringBuffer();

 while (m.find())
 {
 m.appendReplacement(sb, "dog");
 i++;
 }
 m.appendTail(sb);

 System.out.println(sb.toString());
 System.out.println(i);


(fds) {2,} is two or more times fds do ? Is for example : fdsfds fdsfdsfds match such strings do ?
Why did not match the second string aaafdsafds on quite incomprehensible , did not write to match the beginning and end , ah,
Is not that many matches ? But (fds) {2,} + did not match up ah ?
------ Solution ---------------------------------------- ----
fds appear together twice or more than twice
------ For reference only --------------------- ------------------
be consecutive ~ ~
------ For reference only ------------ ---------------------------
want to get your results , it should be (fds *) {2,} < br> ------ For reference only ---------------------------------------
of all to you, a mistake is behind the middle there is a fdsafds did not see , I said, and they understand how inconsistent, get rid of that after a normal, and consistent with their own understanding of the

没有评论:

发表评论