Regex Tester & Extractor

Developer

Test regex patterns in real time, highlight matches, inspect capture groups, and generate code snippets.

Regex Workspace
Matches: 2
HIGHLIGHT RESULT
product-120
order-42
invalid
CAPTURE GROUPS
#Full MatchGroups
1product-120g1: product | g2: 120
2order-42g1: order | g2: 42
Reference

Regex Cheat Sheet

TokenMeaning
.Any character except newline
\dDigit (0-9)
\wWord character
\sWhitespace
^ / $Start / end of line
[abc]Any character in class
[^abc]Any character not in class
( ... )Capture group
(?: ... )Non-capturing group
a|bAlternation
* + ?Quantifiers
{n,m}Range quantifier

Code Snippet

const regex = new RegExp('(\\w+)-(\\d+)', 'g');
const text = 'product-120
order-42
invalid';
const matches = [...text.matchAll(regex.global ? regex : new RegExp(regex.source, regex.flags + 'g'))];
console.log(matches);
Share

You might also like