Missing closing bracket in character class near index 13 |\?*<":>+[]/' My code:
Pattern.compile("|\\?*<\":>+[]/'").matcher(name).matches()
You may use
Pattern.compile("[|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches()
The regex means:
[
- start of a positive character class:
|
- a pipe \\
- a backslash (requires additional backslashes in the string literal, "\\\\"
) ?
- a question mark *
- an asterisk <
- an open angle bracket "
- a double quotationmark :
- a colon >
- a close angle bracket +
- a plus \[
- a [
char (must be escaped when [
is inside a character class) \]
- a ]
char (must be escaped when ]
is inside a character class) /
- a forward slash '
- a single quotation mark ]+
- end of character class, 1 or more occurrences. So, this will validate a string that only consists of 1 or more occurrences of these chars. If you need the opposite, add ^
after the first [
:
Pattern.compile("[^|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches()
// ^
String name = "Wiktor Stribiżew";
System.out.println(Pattern.compile("[^|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches());
// => true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.