Originally posted by Jerry Lee:
I tried this one it doesn't work.
[0-9&&[^a-zA-Z]]
That regex matches
one character that
is a digit and
isn't a letter. You need a regex that matches a whole line, and you need to do the two tests separately. One regex for a line of characters other than letters would be
...and for a line that contains a digit,
You don't need to call matches() twice though, because you can state one of the requirements as a lookahead:
Finally, if you use the matches() method, you don't need the '^' and '$' anchors at either end of the regex, but you
do need the '$' in the lookahead, to make sure it checks the whole line.
By the way, here's a site with a better regex tutorial:
http://www.regular-expressions.info/ [ May 28, 2008: Message edited by:
Alan Moore ]