[SOLVED] Java string.matches() returns wrong statement


I’m running some code through the eclipse debugger and a[1].matches("[a-zA-Z]") is not equating to true when a[1] = "ABCD" (a is a string array).

I’ve read the javadoc on matches and [a-zA-Z] should be a valid regular expression..

Anyone know where I’m going wrong?


Try using this expression: [a-zA-Z]* (will match zero or more characters).

If you require at least one character, use: [a-zA-Z]+

The expression you’re using will only match a single alpha character since it’s not quantified.

Answered By – Rob Hruska

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *