I am really new to regexp so please excuse me if I am not wording the
question correctly.
I am having difficulty in validating a string. This string might have
any of the following formats (# denotes a digit)
#
#:
##:
##:#
##:##
#
#.
##.
##.#
##.##
I tried several permutations and it works with some formats but not
others. I really need it to handle all the formats above how do I build
it
//RE r = new RE("[0-9][0-9]?\\:|\\.[0-9]?[0-9]?");
//RE r = new RE("[0-9][0-9]?\\:|\\.[0-9]?[0-9]?");
RE r = new RE("[0-9]{1,2}\\:|\\.[0-9]?[0-9]?");
// need to return always true
System.out.println(r.match("1"));
System.out.println(r.match("11"));
System.out.println(r.match("11:"));
System.out.println(r.match("11:1"));
System.out.println(r.match("11:11"));
System.out.println(r.match("1"));
System.out.println(r.match("11"));
System.out.println(r.match("11."));
System.out.println(r.match("11.1"));
System.out.println(r.match("11.11"));
//need to return always false if the string has other characters
embedded or does not
// match the pattern
System.out.println(r.match("1a"));
System.out.println(r.match("1a1"));
System.out.println(r.match("11a:"));
System.out.println(r.match("11a:1"));
System.out.println(r.match("11:1a1"));
System.out.println(r.match("a2"));
System.out.println(r.match("22a"));
System.out.println(r.match("22:a"));
System.out.println(r.match("a22a:2"));
System.out.println(r.match("22:2a"));
System.out.println(r.match("333:3"));
System.out.println(r.match("44:444"));
Thanks in advance for any help
Max
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]