> I need a regular expression that checks the contents of a string as
> follows -
If you were to look at the description of a regular expression,
I think you'd be able to construct the answer yourself.

Signature
Chris "electric hedgehog" Dollin
"How am I to understand if you won't teach me?" - Trippa, /Falling/
harryajh - 23 Feb 2007 12:45 GMT
> > I need a regular expression that checks the contents of a string as
> > follows -
[quoted text clipped - 5 lines]
> Chris "electric hedgehog" Dollin
> "How am I to understand if you won't teach me?" - Trippa, /Falling/
I've tried several expressions but I just can't get the right one -
was hoping someone with a lot (I've only just started using them!) of
RE experience could just rattle one off?
thanks again
harry
> I need a regular expression that checks the contents of a string as
> follows -
[quoted text clipped - 24 lines]
>
> 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
harryajh - 23 Feb 2007 12:53 GMT
> > I need a regular expression that checks the contents of a string as
> > follows -
[quoted text clipped - 37 lines]
>
> lester
thanks for that Lester - made a note of giving RE stuff a good bash on
the weekend!
> I need a regular expression that checks the contents of a string as
> follows -
[quoted text clipped - 10 lines]
> cTn8d
> won't!
"^[c|C][t|T][n|N]\d+[\\s|$]"
Z - 24 Feb 2007 05:39 GMT
>> I need a regular expression that checks the contents of a string as
>> follows -
[quoted text clipped - 12 lines]
>
> "^[c|C][t|T][n|N]\d+[\\s|$]"
Oops!
Make that: "^(c|C)(t|T)(n|N)\\d+(\\s|$)" or "^[cC][tT][nN]\\d+[\\s$]"
or maybe even "^[cC][tT][nN]\\d+\\b"
Lew - 24 Feb 2007 05:55 GMT
harryajh wrote:
>> I need a regular expression that checks the contents of a string as
>> follows -
[quoted text clipped - 10 lines]
>> cTn8d
>> won't!
> "^[c|C][t|T][n|N]\d+[\\s|$]"
Don't you mean "^[Cc][Tt][Nn]\d+$"? (Not written as a Java String literal.)
Java expression: String re = "^[Cc][Tt][Nn]\\d+$";
Is this homework?
Either way, you have to experiment with solutions you find here on Usenet. I
could be sadly mistaken, or Z could, or anyone could. OTOH, I did look up one
regex reference before posting this response.
<http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html>
- Lew