Regular Expressions 101

Sponsors

Library entries

-1
pcre2

T

T
Submitted by me - 2 years ago
-1
python

test

d
Submitted by anonymous - a year ago
-1
pcre2

bl_regex_fees_types_2

guif
Submitted by guif - a year ago
-1
pcre2

1

1
Submitted by anonymous - 8 months ago
-1
pcre2

213

12312
Submitted by anonymous - 8 months ago
-1
pcre2

slug numeric

pattern to validate a slug with numbers
Submitted by mestri.rodrigo - 8 months ago
-1
pcre2

is

Hi it is me
Submitted by anonymous - 8 months ago
-2
pcre

Finds HTML img tags

no description available
Submitted by Matt Solum - 9 years ago
-2
pcre

Remove namespaces

no description available
Submitted by anonymous - 9 years ago

match valid JSON

Vote

26

Regular Expression
pcre

/
(?(DEFINE) # Note that everything is atomic, JSON does not need backtracking if it's valid # and this prevents catastrophic backtracking (?<json>(?>\s*(?&object)\s*|\s*(?&array)\s*)) (?<object>(?>\{\s*(?>(?&pair)(?>\s*,\s*(?&pair))*)?\s*\})) (?<pair>(?>(?&STRING)\s*:\s*(?&value))) (?<array>(?>\[\s*(?>(?&value)(?>\s*,\s*(?&value))*)?\s*\])) (?<value>(?>true|false|null|(?&STRING)|(?&NUMBER)|(?&object)|(?&array))) (?<STRING>(?>"(?>\\(?>["\\\/bfnrt]|u[a-fA-F0-9]{4})|[^"\\\0-\x1F\x7F]+)*")) (?<NUMBER>(?>-?(?>0|[1-9][0-9]*)(?>\.[0-9]+)?(?>[eE][+-]?[0-9]+)?)) ) \A(?&json)\z
/
x

Description

Loading markdown...
Submitted by Mateon1 - 8 years ago