I am looking for a Regex that allows me to validate json.
I am very new to Regex\'s and i know enough that parsing with Regex is bad but can it be used to validate?
A trailing comma in a JSON array caused my Perl 5.16 to hang, possibly because it kept backtracking. I had to add a backtrack-terminating directive:
(? \s* (?: (?&number) | (?&boolean) | (?&string) | (?&array) | (?&object) )(*PRUNE) \s* )
^^^^^^^^
This way, once it identifies a construct that is not 'optional' (*
or ?
), it shouldn't try backtracking over it to try to identify it as something else.