Regular Expressions 101

Community Patterns

JSON validator

2

Regular Expression
PCRE (PHP <7.3)

/
(?<o>{((?<s>\"([^\0-\x1F\"\\]|\\[\"\\\/bfnrt]|\\u[0-9a-fA-F]{4})*\"):(?<v>\g<s>|(?<n>-?(0|[1-9]\d*)(.\d+)?([eE][+-]?\d+)?)|\g<o>|\g<a>|true|false|null))?\s*((?<c>,\s*)\g<s>(?<d>:\s*)\g<v>)*})|(?<a>\[\g<v>?(\g<c>\g<v>)*\])
/

Description

Takes a JSON string and captures interesting information in the named capturing groups: (o: last object, a: last array, s: last string, n: last number, c: last comma before optional whitespace, d: same as c, but with a colon instead of a comma, v: last value)

Submitted by luis140219 on GitHub and Sourceforge - 9 years ago