Regex · JavaScript
Best Regex Tester for JavaScript Online
Testing regular expressions in JavaScript? A good regex tester shows you matches highlighted in real time, lets you toggle flags, and displays capture groups clearly. Here's what to look for.
Regex Tester
Test JavaScript regex patterns with live match highlighting and group output. Free and instant.
Open Regex Tester →What makes a good JavaScript regex tester?
- Real-time matching — matches highlight as you type the pattern
- JavaScript engine — uses actual JS regex, not a different flavour
- Flag support — g, i, m, s, u flags easily togglable
- Capture group display — see what each group matched
- Match count — know how many matches were found
- Error display — invalid patterns shown clearly
- No upload, no account — just open and use
JavaScript regex flags explained
| Flag | Meaning | Example use |
|---|---|---|
g | Global — find all matches | Count all occurrences |
i | Case-insensitive | Match "Hello" and "hello" |
m | Multiline — ^ and $ match line start/end | Validate each line of a textarea |
s | Dotall — . matches newlines | Match across line breaks |
u | Unicode — enable full Unicode support | Match emoji, accented chars |
Common JavaScript regex patterns to test
Email validation
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/URL matching
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}[-a-zA-Z0-9@:%_+.~#?&/=]*/gExtract numbers from string
/-?\d+\.?\d*/g
Match camelCase words
/[a-z]+([A-Z][a-z]+)*/g
HTML tag stripper
/<[^>]*>/g
Using regex in JavaScript code
JavaScript regex methods
const str = "Hello World, hello JavaScript"; const pattern = /hello/gi; // Test if pattern matches pattern.test(str); // true // Find all matches str.match(pattern); // ["Hello", "hello"] // Replace matches str.replace(pattern, "Hi"); // "Hi World, Hi JavaScript" // Get match position pattern.exec(str); // ["Hello", index: 0, ...] // Split by pattern "a1b2c3".split(/\d/); // ["a", "b", "c", ""]
Frequently asked questions
Why does my regex work in the tester but not in my code?
The most common reason is forgetting to escape backslashes. In a regex literal (/\d+/) you write \d. In a string passed to new RegExp(), you need \d because the backslash is consumed by the string first. The regex tester uses regex literals, so this difference won't show up there.
Why does .test() return different results on repeated calls?
If your regex has the g flag and you reuse the same regex object, .test() and .exec() remember the last match position (lastIndex). Each call starts from where the last left off. Either use the g flag only with .match() or reset regex.lastIndex = 0 before reusing.
Is JavaScript regex the same as Python regex?
Mostly similar but with differences. JavaScript doesn't support named backreferences with the same syntax, has limited lookbehind support (added in ES2018), and lacks the verbose mode (?x) that Python supports. Always test in the target language.
Try it free — no sign-up needed
Runs entirely in your browser. Nothing uploaded, nothing stored.
Open Regex Tester →