Regular Expressions 101

Community Patterns

Oxford comma

1

Regular Expression
ECMAScript (JavaScript)

/
((?:[\w'-]+,\s+)+(?:[\w'-]+\s){0,2}[\w'-]+)(\s+(and|or)\s+[\w'-]+)
/
gi

Description

Insert comma in lists before the word "and" or "or".

Submitted by Mogsdad w/ assist from TerryAtOpus - 8 years ago