简体   繁体   English

缺少右括号

[英]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 - 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()
//                ^ 

Java demo : Java 演示

String name = "Wiktor Stribiżew";
System.out.println(Pattern.compile("[^|\\\\?*<\":>+\\[\\]/']+").matcher(name).matches());
// => true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何实现自动括弧关闭? - How to implement auto bracket-closing? Java 关闭括号后的拆分方法 - Java split method to split after closing bracket 正则表达式的末尾有一个转义的右括号 - Regular expression wtih an escaped closing bracket at the end 为什么关闭方括号“]”不需要在Java正则表达式中转义? - Why closing square bracket “]” doesn't require escaping in Java regex? 键入时如何正确删除自动添加的右括号 - How to correctly remove the automatically added closing bracket when it is typed Java jstack 示例指向右括号而不是代码行 - Java jstack sample pointing at closing bracket rather than line of code 为什么代码覆盖率有时会计算方法名称或右括号? - Why code coverage sometimes counts method name or closing bracket? Java中的字符串格式,单词的最大宽度和右括号 - String Formatting in java with max width and closing bracket at the end of word Log4j2 JSONLayout不附加右(])方括号 - Log4j2 JSONLayout not appending closing (]) square bracket Java正则表达式:如果结束括号是字符串中的最后一个字符,则匹配圆括号中的任意位数 - Java Regular Expression: match any number of digits in round brackets if the closing bracket is the last char in the String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM