import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MatchChar {
public static void main(String[] args) {
String pattern="[a-z]";
String text="5 a T u 1 2";
Pattern p=Pattern.compile(pattern);
String tt[]=text.split("\\s");
for(int i=0; i < tt.length ; i++){
Matcher m=p.matcher(tt[i]);
System.out.println(m.matches()+"\t"+tt[i]);
}
}
}
Output is :-
false 5
true a
false T
true u
false 1
false 2
No comments:
Post a Comment