Text Processingflags: g
JSON Number (Strict)
Match JSON-spec numbers — disallows leading zeros (no `01`), allows decimals and exponents.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)? (flags: g)Raw source: -?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?
How it works
-? optional sign. (?:0|[1-9]\d*) the integer part: either a single zero or a non-zero digit followed by any digits (no leading zeros allowed per RFC 8259). (?:\.\d+)? optional decimal part. (?:[eE][-+]?\d+)? optional exponent. Strict per JSON spec — won't match `01` or `1.` (which are valid JS but not JSON).
Examples
Input
values: 0, 42, -3.14, 6.022e23Matches
042-3.146.022e23
Input
0.5 vs invalid 01Matches
0.501
Input
no numbersNo match
—Common use cases
- •JSON validators and lexer fallback paths
- •Number-extraction from semi-JSON formats
- •Detecting JS-isms in JSON payloads
- •Quick parsing in observability pipelines
Related patterns
JSON Key-Value Pair (Simple)
Text ProcessingExtract simple `"key": value` pairs from JSON-ish text (strings, numbers, booleans, null).
JSON Boolean / Null Literal
Text ProcessingMatch JSON `true`, `false`, and `null` literal values, with word boundaries to avoid partial matches.
Negative Lookbehind (Decimals Without $)
Text ProcessingUse negative lookbehind `(?<!...)` to match decimal numbers NOT preceded by a dollar sign.
Whitespace Trim (Leading & Trailing)
Text ProcessingMatch leading and/or trailing whitespace on a string — the regex equivalent of .trim().