简体   繁体   中英

Java Pattern regex whole word match

I am trying to match a keyword with following string

"abc,pqr(1),xyz"

It will be succesfull match if the whole one word matched for eg "par" or "abc" or "xyz"

Can anyone please help me in creating regex for this match ?

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);

This Should Work.

([a-zA-Z]+)

Input:

"abc,pqr(1),xyz"

Output:

abc
pqr
xyz

See: https://regex101.com/r/Us6G3X/2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM