ToolsHubs
ToolsHubs
Privacy First

Regex Tester

Test and debug regular expressions in real-time with match highlighting, flags support, and quick examples.

How to use Regex Tester

  1. 1

    Enter your regular expression pattern.

  2. 2

    Set flags (g, i, m, etc.).

  3. 3

    Type or paste your test string and see matches highlighted in real-time.

Frequently Asked Questions

Which regex flags are supported?

g (global — find all matches), i (case insensitive), m (multiline — ^ and $ match line breaks), s (dotAll — . matches newlines), u (unicode — full Unicode support), y (sticky — matches from lastIndex). You can combine multiple flags.

Is this JavaScript regex or a different engine?

This uses the JavaScript RegExp engine specifically. Regex syntax varies slightly between languages — Python's re module, Java's Pattern, and PCRE have minor differences. Patterns written here will work in any JavaScript/Node.js environment.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, ?) match as many characters as possible. Lazy quantifiers (*?, +?, ??) match as few as possible. Example: /<.+>/ on "<a>text</a>" matches the whole string. /<.+?>/ matches just "<a>".

How do I match a literal dot or brackets?

Special characters must be escaped with a backslash. To match a literal dot: \. To match a literal bracket: \[ or \]. To match a literal backslash: \\.

Can I test for email or phone number patterns here?

Yes — common patterns: email: ^[\w.-]+@[\w.-]+\.[a-z]{2,}$, phone (India): ^[6-9]\d{9}$, URL: ^https?:\/\/[\w/-]+. Paste the pattern and your test string to verify matches.

Why does my regex work here but fail in my code?

Check string escaping. In JavaScript source code, backslashes inside RegExp strings need to be doubled (\\ for a literal \). In regex literals (/pattern/), single backslashes work. The tester shows the regex directly, so no extra escaping is needed here.

Write It Once, Get It Right

Regular expressions are compact but unforgiving. A single misplaced character changes what matches. Testing a regex by running a script, checking the output, adjusting, and running again wastes minutes per iteration. This tester closes that loop: type your pattern, paste your test string, and every match highlights instantly as you type.


Regex Syntax Quick Reference

PatternMatches
.Any character except newline
\dDigit (0–9)
\wWord character (a–z, A–Z, 0–9, _)
\sWhitespace (space, tab, newline)
^Start of string (or line with m flag)
$End of string (or line with m flag)
*Zero or more of the preceding
+One or more of the preceding
?Zero or one (also: lazy quantifier)
{n,m}Between n and m repetitions
[abc]Any of a, b, or c
[^abc]Not a, b, or c
(...)Capturing group
(?:...)Non-capturing group
(?=...)Positive lookahead
``

Flags

FlagEffect
gGlobal — find all matches, not just the first
iCase-insensitive matching
mMultiline — ^ and $ match line starts/ends
sDot-all — . also matches newlines
uUnicode mode — full Unicode character support

Practical Regex Patterns You Can Use Now

Email validation:

^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$

Phone number (international format):

^\+?[1-9]\d{6,14}$

Date (YYYY-MM-DD):

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

IPv4 address:

^(\d{1,3}\.){3}\d{1,3}$

HTTP/HTTPS URL:

^https?:\/\/[^\s/$.?#].[^\s]*$

Extract JSON string values:

"([^"]+)":\s*"([^"]+)"

Paste these into the pattern field and test them against your own strings to see exactly which parts match.


Real-World Uses

Form validation: Test email, phone, and postal code patterns before embedding them in your validation logic. Try both valid and invalid inputs to confirm both-direction correctness.

Log parsing: Extract timestamps, IP addresses, HTTP status codes, and request paths from server log lines without writing full parser code.

Code search and replace: Many editors support regex in find/replace. Build and test complex replacement patterns — with capture group references — before applying to source code.

Data extraction: Pull specific fields from structured text. A (\d{4}-\d{2}-\d{2}) pattern in a capturing group extracts the date string from any surrounding text.

Input sanitization: Test what patterns match user input that should be blocked — usernames with invalid characters, inputs containing script tags, or content exceeding length limits.


Common Pitfalls

Greedy vs. lazy matching. By default, .* is greedy — it matches as much text as possible. .*? is lazy — it stops at the first opportunity. When matching between delimiters like <b>text</b>, use .+? not .+ to avoid consuming both the opening and closing tags.

Forgetting the global flag. Without g, the tester only highlights the first match. Add g to see all matches in the test string.

Not anchoring validation patterns. \d+ matches any substring of digits — it'll match the numbers inside abc123def. For full-string validation, anchor with ^\d+$.

Catastrophic backtracking. Certain patterns ((a+)+ applied to aaaaaaa!) cause exponential matching attempts — freezing the browser or server. Avoid overly nested quantifiers in patterns that process untrusted input. Test with adversarial inputs.

JavaScript regex differs from PCRE. Patterns from Python, PHP, or Perl tutorials may use features not supported in JavaScript — possessive quantifiers, certain lookbehind constructs, or some Unicode properties. Always test in the environment you'll deploy in.


Related Developer Tools


Recommended schema: SoftwareApplication + FAQPage