Java regular expression word match

前端 未结 5 652
孤街浪徒
孤街浪徒 2021-01-25 15:05

I have 3 values IU, PRI and RET. if my input string contains any one or more value(s),
the Java regular expression should return true.

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 15:51

    You need word boundaries for that:

    boolean foundMatch = false;
    Pattern regex = Pattern.compile("\\b(?:UI|PRI|RET)\\b");
    Matcher regexMatcher = regex.matcher(subjectString);
    foundMatch = regexMatcher.find();
    

提交回复
热议问题