java - 正则表达式查找整个单词

标签 java regex

如果字符串 "I am in the EU." 中存在一个完整的词,即 "EU",我将如何查找,同时不匹配像这样的情况“我在欧洲。”?

基本上,我想要某种正则表达式来表示单词,即 “EU” 两边都带有非字母字符。

最佳答案

.*\bEU\b.*

 public static void main(String[] args) {
       String regex = ".*\\bEU\\b.*";
       String text = "EU is an acronym for  EUROPE";
       //String text = "EULA should not match";


       if(text.matches(regex)) {
           System.out.println("It matches");
       } else {
           System.out.println("Doesn't match");
       }

    }

关于java - 正则表达式查找整个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12574853/

相关文章:

java - 正则表达式无法正确匹配多个单词

java - 使用Redis或其他DB时应在获取之前调用hasKey方法

java - 在 Java 中将单词拆分为字母

java - 在Java中动态加载一个类

java - @Pattern with Unicode script\\p{L}* 不起作用

PHP 正则表达式 : CSS Relative to Absolute

java - Android Facebook SDK 使用 OnSelectionChangeListener 获取选定用户时出现问题

java - NetBeans 中的项目版本控制

javascript - 使用javascript从url中提取数字?

python - 理解 python 中正则表达式的原始字符串