[英]Missing closing bracket
Missing closing bracket in character class near index 13 |\?*<":>+[]/' My code:在索引 13 |\?*<":>+[]/' 附近的字符 class 中缺少右括号 我的代码:
Pattern.compile("|\\?*<\":>+[]/'").matcher(name).matches()
You may use您可以使用
Pattern.compile("[|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches()
The regex means:正则表达式的意思是:
[
- start of a positive character class: [
- 正字符 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. ]+
- 字符 class 结束,出现 1 次或多次。 So, this will validate a string that only consists of 1 or more occurrences of these chars.因此,这将验证仅包含 1 次或多次出现这些字符的字符串。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.