Matching a whole word with leading or trailing special symbols like dollar in a string

后端 未结 4 1403
面向向阳花
面向向阳花 2020-12-19 05:36

I can replace dollar signs by using Matcher.quoteReplacement. I can replace words by adding boundary characters:

from = \"\\\\b\" + from + \"\         


        
4条回答
  •  情话喂你
    2020-12-19 05:59

    Matcher.quoteReplacement() is for the replacement string (to), not the regex (from). To include a string literal in the regex, use Pattern.quote():

    from = Pattern.quote(from);
    

提交回复
热议问题