Advanced Examples
[\s\S]
is a hack to match any character including newlines. We avoid the dot-all flag because we need to use the ordinary .
for single-line comments.
24-Hour Time
Replace: <Example regex={/$1/$2}>
I performed this operation in commit d7a684f
.
Floating point numbers
- optional sign
- optional integer part
- optional decimal part
- optional exponent part
The positive lookahead (?=\.\d|\d)
ensures that the regex does not match .
.
Latitude and Longitude
See also: Floating Point Numbers
MAC Addresses
UUID
IP Addresses
HSL colours
Integers from 0
to 360
360
300
to 359
— 3
, [0-5]
, any digit0
to 299
- optionally
1
or 2
as the hundreds digit - optionally any tens digit
- a units digit
Percentages
100
, optionally followed by .000…
- one or two digit integer, optionally followed decimal part
Bringing it all together