I have to use java regex to match string like this: [] [a1] ,[abdf123] ...:
that is ,a brackets with a string inside it, this inside string is empty ,or it has to be like this: aaa123, a12, b34, that is , a sequence of letters, and then a sequence of digits.
So I write the regex like this:
Pattern.matches("^(\\[)[|[a-zA-Z]+(\\d+)](\\])$","[abc123]");
But to my surprise ,it returns false. To test if [a-zA-Z]+(\d+) can correctly match the string inside the [],I write the regex like this:
Pattern.matches("^[a-zA-Z]+(\\d+)$","abc123");
it returns true;
Anybody can explain this for me?thanks.