Regular Expressions 101

Sponsors

Library entries

1
java

IP Address

(^([0-9]{2,3}.)([0-9]{2,3}.)([0-9]{2,3}.)([0-9]{2,3})$)
Submitted by anonymous - 6 days ago
0
pcre

Intervelead 2 of 5 custas

Intervelead 2 of 5 custas
Submitted by anonymous - 9 days ago
0
python

Code Block Splitting

Useful for getting codeblock from a text
Submitted by anonymous - 9 days ago
0
golang

nginx access regex loki

nginx access log regex
Submitted by Lethisa Putri - 10 days ago
0
python

singleTime ztm

ss
Submitted by pochwix2 - 11 days ago
0
python

Contas regex

A simple regex for contas bancárias
Submitted by anonymous - 12 days ago
0
python

Out of

Out of
Submitted by anonymous - 13 days ago
0
pcre

test1

test1
Submitted by anonymous - 15 days ago
1
python

telephone_founder

with obfuscation
Submitted by anonymous - 17 days 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