Regular Expressions 101

Library entries

JSON Validation (RFC-8259)

Vote

1

Regular Expression
pcre

/
(?(DEFINE) # JSON does not need backtracking if it's valid # so everything is atomic to prevent backtracking # regex is built per https://tools.ietf.org/html/rfc8259 (?<json>(?>\s*(?&object)\s*|\s*(?&array)\s*)) (?<object>(?>\{\s*(?>(?&member)(?>\s*,\s*(?&member))*)?\s*\})) (?<member>(?>(?&string)\s*:\s*(?&value))) (?<array>(?>\[\s*(?>(?&value)(?>\s*,\s*(?&value))*)?\s*\])) (?<value>(?>)false|null|true|(?&object)|(?&array)|(?&number)|(?&string)) (?<number>(?>-?(?>0|[1-9][0-9]*)(?>\.[0-9]+)?(?>[eE][-+]?[0-9]+)?)) (?<string>(?>"(?>\\(?>["\\\/bfnrt]|u[a-fA-F0-9]{4})|[^"\\\0-\x1F\x7F]+)*")) ) \A(?&json)\z
/
x

Description

Loading markdown...
Submitted by anonymous - a year ago