Do I always need to escape metacharacters in a string that is not a “literal”?

后端 未结 4 1530
耶瑟儿~
耶瑟儿~ 2021-01-12 13:53

It seems that having a string that contains the characters { or } is rejected during regex processing. I can understand that these are reserved cha

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 14:14

    You can use

    java.util.regex.Pattern.quote(java.lang.String)
    

    to escape meta characters used by regular expressions.

提交回复
热议问题