harryajh said:
I need a regular expression that checks the contents of a string as
follows -
The string must -
begin with the letters "CTN" but can be case insensitive
must be followed by at least one number possibly more
so
CTN1
CTN123
ctN1
will pass the check but
xCTN1
CTNk
cTn8d
won't!
can anyone help?
thanks
harry
have you tried:
Pattern p = Pattern.compile("^(C|c)(T|t)(N|n)\d+.*");
Matcher m = p.matcher("<yourstring>");
boolean b = m.matches();
if no furter characters are following the "CTN5<digits>.." string then
omit the '.*' clause at the end of the regular expression.
else, please look at the documentation of the javax.util.regex.Pattern
class in the j2se api.
lester