Grab a list of words that don't contain an oxford comma

I am trying to highlight parts of an essay that include a list of three or more words, but not the Oxford comma. The regular expression that I came up with is the following:

([a-z]+)(,\s*[a-z]+)(\s*or|and+)(\s*[a-z])

But it does not work. Any thoughts on how to do this?

He must fix "red, white and blue", but not"red, white, and blue"

+4
source share
2 answers

, . (\s*or|and+) \s* , and , + ( anddd - ). (\s*[a-z]) +, .

, - , :

([a-z]+)((?:,\s*[a-z]+)*)\s+(and|or)\s+([a-z]+)

IDEONE.

+1

RegEx

\w+(?:,\s*\w+)*\s+(?:and|or)\s+\w+

. .

0

All Articles