Regex for trailing comma

/,(?=\s*[\]}])/g

Options
Matches

Examples

Note

The lookahead finds commas followed by a closing bracket without consuming it. Replace with nothing to clean up near-JSON.

Matches in the example

  • ","
  • ","

Token by token

  1. , the character “,”
  2. (?= followed by (lookahead, not consumed)
  3. \s* a whitespace character, zero or more times, as many as possible
  4. [\]}] one of: the character “]” or “}”
  5. ) end of group

Other patterns