Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?(DEFINE) (?<quote>['"]) (?<pair> (?> \w+ |(?: (?<pairQuote>(?&quote))[^'"]+?\k<pairQuote> ) ) \s*\: ) (?<string> (?<stringQuote>(?&quote))[\S\s]*?(?<!\\)\k<stringQuote> ) (?<integer>\-?\d+(?:\.\d+)?(?:e[-+]\d+)?) (?<scalar>true|false|null|(?&integer)) (?<elements> \s*(?&value) (?(R&array)|(?>(?:\s*\,(?&elements))|\s*)) ) (?<array>\[(?>(?&elements)|\s*)\]) (?<value> (?&object) |(?&string) |(?&scalar) |(?&array) ) (?<members> \s*(?&pair)\s*(?&value) (?(R&object)|(?>(?:\s*\,(?&members))|\s*)) ) (?<object>\{(?&members)?\}) ) \A(?&object)\Z
/
gimx

Description

Complete (recursive) JSON validation regular expression.

Submitted by @Erutan409 - 9 years ago