When I am trying to execute the below code
text.matches("[a-zA-Z0-9 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]");
I am getting exception
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 43
[a-zA-Z0-9 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.clazz(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.matches(Unknown Source)
at java.lang.String.matches(Unknown Source)
at test.G3Utils.checkIsAttribANS(G3Utils.java:47)
at test.G3Utils.main(G3Utils.java:6)
Please help me to solve this
,-.are next to each other in the ASCII table, so the range from comma to dot is the same as specifying those 3 characters. Usually, it's less confusing to write-at the end of the character class.