Community Patterns

Community Library Entry

1

Regular Expression
Created·2014-07-26 11:37
Flavor·PCRE (Legacy)

/
["](""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?(""[^"]*""|[^",]*)[,]?["]
/
g
Open regex in editor

Description

Regex to remove commas within quotes. (Common situtaion in .csv files)

Eg: data,"some ""embedded"" stuff,commas,inside,quotes",more

Replace String would be something like this: \1&\2&\3&\4&\5&\6&\7&\8&\9

which would replace the commas inside the quotes with '&'s Caveats:

  • embedded quotes ("") remain in the matches
  • limit of 9 terms within quotes

Work in progress ...

Submitted by Judd