Java Pattern正则表达式全字匹配

时间:2017-02-01 15:27:07

标签: java regex pattern-matching

我正在尝试将关键字与后续字符串匹配

" ABC,PQR(1),XYZ"

如果整个单词与例如匹配,则将成功匹配"帕"或" abc"或" xyz"

任何人都可以帮我为这场比赛创建正则表达式吗?

String text    = "hello, hellos(1),bye";
    String keyword = "account";
    String patternString = "["+ keyword + "]";

    Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);

    Matcher matcher = pattern.matcher(text);

    boolean matches = matcher.matches();

    System.out.println("matches = " + matches);

1 个答案:

答案 0 :(得分:0)

这应该有效。

([a-zA-Z]+)

输入:

"abc,pqr(1),xyz"

输出:

abc
pqr
xyz

请参阅:https://regex101.com/r/Us6G3X/2