I’ve to create a java regex that disable creation of databases.
(I’m following these restrictions: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html)
Can anyone help me to build a regex with this restriction [0-9,a-z,A-Z$_] ?
This is my snippet:
Pattern pattern = Pattern.compile("[0-9a-zA-Z$_]");
Matcher matcher = pattern.matcher("userdatabase");
System.out.println(matcher.matches());
You didn’t specify a quantifier. Your expression will only match one character.
Try changing it to:
The
+indicates that it should be that expressions 1 or more times.