Java regular expression word match

前端 未结 5 588
孤街浪徒
孤街浪徒 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:48

    Try

    String s= "A IU somehting PRI something RET whatever";
    
    Pattern p= Pattern.compile("(IU|PRI|RET)");
    Matcher m= p.matcher(s);
    while (m.find()) {
        String matched= m.group(1);
        System.out.println(matched);
    }
    

    It prints:

    IU
    PRI
    RET
    

提交回复
热议问题