Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 521
Michael Avatar asked Jan 19 '23 21:01

Michael


1 Answers

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.

like image 114
Rob Hruska Avatar answered Jan 25 '23 06:01

Rob Hruska