0

Related to this question Regex to match commas that are not in an array (enclosed in square brackets) I found I want to match commas outside of curly brackets.

The solution to that question was ,(?![^[]*\]). I am trying a similar regex, ,(?![^{]*\}), for my problem.

What I found with this regex I am trying is that it doesn't match the third comma in this example, {"A": "B", "C":{"D":"E"}, "F": {"G"}, "H":"I"}. For some reason it does not match the last comma after the closing curly bracket following the letter G.

The example online: https://regex101.com/r/4YXKqJ/1

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Ilias Karim
  • 4,798
  • 3
  • 38
  • 60

1 Answers1

1

Is this for PCRE like in your demo? If so, consider skipping the {...} parts:

{[^}{]*}(*SKIP)(*F)|,

See this demo at regex101

The left side of the alternation is used to skip stuff, the right side to match.

bobble bubble
  • 16,888
  • 3
  • 27
  • 46