我有 3 个值IU、PRI 和RET。如果我的输入字符串包含任何一个或多个值,
Java 正则表达式应该返回 true。
Ex:
Values : IU PRI RET
Input String : "put returns UI between paragraphs"
输入字符串包含“UI”单词,Java 正则表达式应返回 true。
最佳答案
您需要word boundaries为此:
boolean foundMatch = false;
Pattern regex = Pattern.compile("\\b(?:UI|PRI|RET)\\b");
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.find();
关于Java正则表达式单词匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165689/