Error compiling a verbose Java regex with character class and word boundary
问题 Why does this pattern fail to compile : Pattern.compile("(?x)[ ]\\b"); Error ERROR java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 8 (?x)[ ]\b ^ at java_util_regex_Pattern$compile.call (Unknown Source) While the following equivalent ones work? Pattern.compile("(?x)\\ \\b"); Pattern.compile("[ ]\\b"); Pattern.compile(" \\b"); Is this a bug in the Java regex compiler, or am I missing something? I like to use [ ] in verbose regex instead of backslash