use Java Regex (only available on JDK 1.4)...
here is my code :
/*****************************************************************
import java.util.regex.*;
public class MyRegex {
public static void main(String[] args) {
myInput = "23AM";
myRegex = "^([0-9]{1,2})([AP]M)$" ;
// this regex mean : match only with a string that have 1 or 2 num chars and
//followed by a/A or p/P and m/M ....
myPattern = Pattern.compile(myRegex);
myMatcher = myPattern.matcher(myInput);
if(myMatcher.find()){
System.out.println("Matched "+ myMatcher.groupCount());
for(int i=0; i <= myMatcher.groupCount(); i++) {
// print the matched, 0th index for indicates the global matching
System.out.println(i+" "+myMatcher.group(i));
}
} else
{
// input was invalid / not matched / not found
System.out.println("Unmatched");
}
}
private static String myRegex ; // string that contain regex pattern ;
private static Pattern myPattern ;
private static String myInput ;
private static Matcher myMatcher ;
}