Java Regex Word Boundaries

后端 未结 1 435
夕颜
夕颜 2021-01-18 09:25

Hi I have the following code which is meant to find the word \"is\" but not when it is within another string so the word \"this\" should not return a match so I use \\b. But

相关标签:
1条回答
  • 2021-01-18 09:45

    Double escape it:

    Pattern p = Pattern.compile("\\bis\\b");
    

    Regex in Java requires you to doubly escape certain special regex symbols, one escaping for Java and another for underlying regex engine.

    0 讨论(0)
提交回复
热议问题