import java.util.regex.*;
class Regex {
public static void main(
String [] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
System.out.println("Pattern is " + m.pattern());
while(b = m.find()) {
System.out.println(m.start() + " " + m.group());
}
}
}
********************************************
%
java Regex "\d\w" "ab4 56_7ab"
Produces the output
Pattern is \d\w
4 56
7 7a
*********************************************
% java Regex "\w\d" "ab4 56_7ab"
Produces the output
Pattern is \w\d
1 b4
4 56
6 _7
In the above the 2 outputs are quite different. Can somebody explain the outputs wrt the combination if \d\w and \w\d..i understand the difference between \d and \w but dont get it when used in combination. Thanks!
[ January 17, 2008: Message edited by: sridhar row ]