How to find the exact word using a regex in Java?

前端 未结 6 1930
既然无缘
既然无缘 2020-11-30 07:01

Consider the following code snippet:

String input = \"Print this\";
System.out.println(input.matches(\"\\\\bthis\\\\b\"));

Output



        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 07:04

    System.out.println(input.matches(".*\\bthis$"));

    Also works. Here the .* matches anything before the space and then this is matched to be word in the end.

提交回复
热议问题