String pattern matching problem in Java

前端 未结 2 1552
春和景丽
春和景丽 2021-02-18 20:45

In my program when I\'m using

line.replaceAll(\"(\", \"_\");

I got a RuntimeException:

 at java.util.regex.Pattern         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-18 21:35

    The error message above the stack trace is (somewhat) helpful:

    Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed group near index 1 ( ^

    (That's what I get in Java 6.) It mentions "regex", "group", and the parenthesis. If you can't see this message, you should check how you're logging/catching/displaying exceptions. It could save you some trouble in the future.

提交回复
热议问题