Hi all,
import java.util.regex.*;
public class Test4 {
public static void main(
String[] args) {
Pattern p=Pattern.compile("\\d*");
Matcher m=p.matcher("ab34ef");
while (m.find()) {
System.out.print(m.start()+m.group()+"\n");
}
System.out.println("------");
Pattern p2=Pattern.compile(".*xx");
Matcher m2=p2.matcher("yyxxxyxx");
while (m2.find()) {
System.out.print(m2.start()+"->"+m2.group()+"\n");
}
System.out.println("------");
String s="ab.cde.fg";
String[] tokens=s.split("\\.");
for(String s2 : tokens) System.out.println(s2);
}
}
Output:
0
1
234
4
5
6(???)
------
0->yyxxxyxx(???)
------
ab
cde
fg
Q1:Why I get value 6 in the last iteration? I think it should loop up to 5.
Q2:Can anybody explain more detail how it works?
Q3:I mixed up all concepts of "\d", "\\d", ".", "\." and "\\." Can anybody explain them how to use in the code?
Thanks a lot.