/ /Regex Tester

Regex Tester

Test and debug regular expressions in real-time. Supports all major flags, replace, and split operations.

Inputs

Test String
Regex Pattern
Flags

Results

Enter a pattern and test string, then click Run.

Related Tools

References

Frequently Asked Questions

What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern, used for pattern matching within strings.
What is the difference between `*` and `+` quantifiers?
`*` matches zero or more occurrences of the preceding element, while `+` matches one or more occurrences.
How do anchors `^` and `$` work?
`^` matches the start of a string, and `$` matches the end. Use them to enforce full-string matching.
What are character classes?
Character classes like `[a-z]` match any character in the set. `\d` matches digits, `\w` matches word characters, `\s` matches whitespace.
What is the difference between capturing and non-capturing groups?
Capturing groups `(...)` store matched substrings for backreference. Non-capturing groups `(?:...)` group patterns without storing.
How do lookahead and lookbehind work?
Lookahead `(?=...)` asserts what follows; negative lookahead `(?!...)` asserts what does not follow. Lookbehind `(?<=...)` and negative lookbehind `(?<!...)` work similarly for preceding text.
What do the `g`, `i`, `m`, `s`, and `u` flags do?
`g` (global) finds all matches. `i` makes matching case-insensitive. `m` makes `^`/`$` match line boundaries. `s` makes `.` match newlines. `u` enables Unicode support.
How do I match a literal dot or special character?
Escape special characters with a backslash: `\.` matches a literal dot, `\*` matches a literal asterisk.
What is the difference between `test()` and `exec()`?
`test()` returns boolean if a match exists. `exec()` returns an array with match details, including index and groups.
What are common regex patterns for email validation?
A simple email pattern: `/^[\w.-]+@[\w.-]+\.\w{2,}$/`. For production, use a library like `validator.js`.
How do I match repeated words?
Use backreferences: `\b(\w+)\s+\1\b` matches a word repeated consecutively.
What is regex alternation?
Alternation using `|` allows matching one pattern or another, e.g., `cat|dog` matches either "cat" or "dog".
How do I make a regex lazy instead of greedy?
Add `?` after quantifiers: `*?`, `+?`, `??`, `{2,}?` matches as little as possible.
What are possessive quantifiers?
Possessive quantifiers (`*+`, `++`, `?+`) prevent backtracking, improving performance but potentially causing no match.