Regex tester: test JavaScript regular expressions
Test regular expressions live: highlighted matches, capture and named groups, flags and clear errors. Runaway patterns are stopped after 1 second.
Runs on your deviceRuns entirely in your browser: nothing you type or upload leaves your device.
How to use it
- Type your pattern without the slashes and tick the flags you need (g, i, m, s, u, y).
- Paste the text to test: matches are highlighted as you type.
- Check the table for each match's position and capture groups.
Testing a pattern before it goes into code
A regular expression, or regex, is a short pattern that describes text: "three digits, a dot, three digits", "a word followed by @". It is used to validate form fields, pull data out of logs, clean up exports and search and replace in editors. A small mistake in the pattern matches too much or too little, and that is hard to see in code.
Here you type the pattern and a sample text and see every match highlighted as you type, with its position and the parts captured by each group in brackets. It all runs in your browser; the pattern and the text aren't sent anywhere.
Example: why `\w` misses Spanish names
The page starts with the pattern (\w+)@(?<domain>[\w.]+) and the text Write to ana@example.com or luis@test.co. The result says 2 matches. In the table, the first row has Position 9, the match ana@example.com, group 1: ana and the named group domain: example.com. The position counts characters from 0, so 9 means it starts at the tenth character.
Now change the text to Escríbele a josé.pérez@correo.co. The match is only rez@correo.co. In JavaScript, \w means only a to z, A to Z, digits and _, so é stops it, and the dot isn't allowed in the first group either. For Spanish text, use [\p{L}\p{N}._]+ with the u flag: \p{L} means any letter, with or without accent, including ñ.
Where tests and reality differ
This is the JavaScript engine of your browser. Python, PHP, Java and .NET share most of the syntax, but not all of it, so test again in the language where the pattern will run. The tool finds matches only; it doesn't do replacements.
Anchors change everything: without ^ and $, a check for a Colombian mobile number such as 3\d{9} also accepts a longer string that merely contains ten such digits. And a pattern that passes on your sample can still be too slow on long text. If the tester stops after 1 second, simplify the pattern before it freezes a real page or server.
FAQ
Which regex flavor is this?
JavaScript (ECMAScript), using your browser's own engine. Most syntax matches PCRE, Python and Java, but features like possessive quantifiers and some lookbehind rules differ.
Why did it stop after 1 second?
Some patterns, like (a+)+$, can take exponential time on certain inputs (catastrophic backtracking). The tester runs them in a separate worker and stops them so the page doesn't freeze; the same pattern could hang your app.
Why doesn't it match when I paste /pattern/gi?
The field takes the pattern without the slashes, which are already drawn around it, and the flags go in the checkboxes. If you paste `/hola/gi`, the tester looks for the literal text `/hola/gi`, slashes included. Paste `hola` and tick g and i.
What do the flags g, i, m, s, u and y mean?
g finds all matches instead of the first. i ignores case. m makes ^ and $ work on each line. s lets the dot match line breaks. u turns on full Unicode, needed for \p{L} and emoji. y (sticky) only matches exactly where the previous match ended.
How do I match prices written like $1.250.000?
Try `\$\d{1,3}(?:\.\d{3})*` with the g flag. On `Total: $1.250.000 y envío $12.000` it finds `$1.250.000` and `$12.000`. The dot is escaped as `\.` because an unescaped dot means any character.
More in this chapter
- 5.1JSON formatterFormat or minify JSON and find syntax errors by line and column.
- 5.2CSV to JSON converterConvert CSV to JSON or JSON to CSV with comma, semicolon or tab separators.
- 5.3YAML to JSON converterConvert YAML to JSON and back in your browser.
- 5.4Base64Encode or decode Base64 in your browser: UTF-8 text, URL-safe Base64, files to Base64 or data URLs, and Base64 back to a downloadable file.
- 5.5Color contrast checkerCheck the contrast ratio of a text color on its background against WCAG 2.2 AA and AAA, for normal text, large text and UI components.
- 5.6Cron explainerRead a 5-field cron expression as a plain sentence and see its next 5 run times in your time zone.
- 5.7Number base converterConvert whole numbers between decimal, hexadecimal, binary and octal, with bit length and grouped digits.
- 5.8HTML entity encoderEncode text as HTML entities (named, decimal or hex) or decode entities back to text: <, >, &, quotes, Spanish accents, Latin-1 symbols.
- 5.9URL encodePercent-encode or decode URLs and query values, and break any URL into protocol, host, path, query parameters and fragment.
- 5.10SHA-256 hashGet SHA-1, SHA-256, SHA-384 and SHA-512 hashes of text or files and verify a download against its published checksum.
- 5.11UUID generatorGenerate random UUID v4 or time-ordered UUID v7 (RFC 9562) in your browser, 1 to 1000 at a time, in uppercase or without dashes.
- 5.12Unix timestampConvert Unix timestamps in seconds or milliseconds to ISO 8601, UTC and your local time, or a date back to epoch.
- 5.13JWT decoderDecode a JSON Web Token in your browser: see the header and payload as formatted JSON and whether it has expired.
╌╌ END ╌╌