Thursday, 15 July 2010

java - Regex to match a word in CSV -



java - Regex to match a word in CSV -

how match word in comma separated values (csv) string single space after each comma.

let's say:

string = 'abc, def, ghijk, l, mn, opqr, stu';

what regex match finish word in above string?

edit: lets want match ghijk given string.

to match words followed comma , exactly 1 space:

\b\w+(?=$|,[ ](?![ ]))

see demo

to retrieve matches:

pattern regex = pattern.compile("\\b\\w+(?=$|,[ ](?![ ]))"); matcher regexmatcher = regex.matcher(your_original_string); while (regexmatcher.find()) { // matched text: regexmatcher.group() }

java regex

No comments:

Post a Comment