[英]Missing closing bracket
在索引 13 |\?*<":>+[]/' 附近的字符 class 中缺少右括号 我的代码:
Pattern.compile("|\\?*<\":>+[]/'").matcher(name).matches()
您可以使用
Pattern.compile("[|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches()
正则表达式的意思是:
[
- 正字符 class 的开头:
|
- pipe\\
- 一个反斜杠(需要在字符串文字中添加额外的反斜杠, "\\\\"
)?
- 一个问号*
- 一个星号<
- 一个开放的尖括号"
- 双引号:
- 一个冒号>
- 右尖括号+
- 一个加号\[
- 一个[
字符(当[
在字符类中时必须转义)\]
- 一个]
字符(当]
在字符类中时必须转义)/
- 正斜杠'
- 一个单引号]+
- 字符 class 结束,出现 1 次或多次。 因此,这将验证仅包含 1 次或多次出现这些字符的字符串。 如果您需要相反的内容,请在第一个[
之后添加^
:
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.