Assuming that you want to match
and -
and not ]
:
Pattern pattern = Pattern.compile("^[a-zA-Z300-3770-9u0153346 u002F.'\\-]*$");
You need to double escape your backslashes, as
is also an escape character in regex. Thus \]
escapes the backslash for java but not for regex. You need to add another java-escaped
in order to regex-escape your second java-escaped
.
So \\
after java escaping becomes \
which is then regex escaped to
.
Moving -
to the end of the sequence means that it is used as a character, instead of a range operator as pointed out by Pshemo.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…