Find a number before px
\d+(?=px)With g and text width: 24px; gap: 8px, matches are 24 and 8. The lookahead checks px without including it.
Text & Code
Test JavaScript regular expressions with live match highlighting, capture groups, named groups, match positions, and replacement preview.
Character classes
. Any char (except newline)\w Word char [a-zA-Z0-9_]\d Digit [0-9]\s Whitespace\W \D \S Negations[abc] Character set[^abc] Negated set[a-z] RangeQuantifiers
* 0 or more+ 1 or more? 0 or 1{n} Exactly n{n,} n or more{n,m} Between n and m*? +? ?? Lazy (non-greedy)Groups & anchors
(abc) Capture group(?<name>abc) Named group(?:abc) Non-capture group(?=abc) Lookahead(?!abc) Neg. lookahead(?<=abc) Lookbehind^ $ Start / end\b \B Word boundaryFlags
g Global (all matches)i Case-insensitivem Multiline (^ $ per line)s DotAll (. matches \n)u Unicode modev Unicode sets (ES2024)d Indices (hasIndices)Quick examples
The Regex Tester evaluates a JavaScript regular expression against sample text and shows all matches highlighted inline. Each match is listed with its position, full value, numbered capture groups, and named capture groups. The replacement tab previews how String.prototype.replace() would transform the input. All processing happens in your browser using the native ECMAScript RegExp engine.
Patterns are compiled with new RegExp(pattern, flags). Matches are found using re.exec() in a loop. At most 5000 matches are displayed, and zero-length global matches advance by a character. The global flag controls whether one or all matches are returned. Named groups are exposed via match.groups in supporting browsers. The d flag adds match indices; it is not required for named groups.
\d+(?=px)With g and text width: 24px; gap: 8px, matches are 24 and 8. The lookahead checks px without including it.
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})For 2026-10-18, year is 2026, month is 10, and day is 18. This checks shape, not calendar validity.
catWith text cat dog cat and no flags, only the first cat matches. Enable g to see both.
a++), atomic grouping ((?>...)), and branch reset groups ((?|...)) are unsupported in JavaScript.g, only the first match is returned.\d not \\d — the tool handles no double-escaping.v flag (Unicode sets) requires Chrome 112+, Firefox 116+, Safari 17+.