Regex Tester Online
Test regex patterns against sample text with live match highlighting. Enter a pattern and test string — all matches are shown instantly with position information. Works with JavaScript and Python regex syntax.
How to Use
Regex Flags Explained
Without the g flag, the regex stops at the first match. Enable g to find every occurrence. Combine flags freely — for example, gi finds all matches regardless of case.
Worked Example
Pattern: \b\d{4}\b Flags: g
Test string: "Invoice #1234 dated 2026 for order 5678 and ref 99"
Matches: 1234, 2026, 5678 (3 matches — "99" is only 2 digits so it does not match)
Frequently Asked Questions
What is a regular expression?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regex is used for string matching, input validation, search-and-replace operations, and text parsing. Most programming languages — JavaScript, Python, Java, Go, Ruby — support regex natively.
How do I test a regex pattern?
Enter your regex pattern in the pattern field (without the surrounding slashes). Type or paste your test string in the Test String box. Matches are highlighted in yellow immediately. The match count shows how many matches were found, and the match list shows each match and its position.
What does the g flag do in regex?
The g (global) flag makes the regex find all matches in the string rather than stopping at the first match. Without g, the regex engine returns only the first occurrence. Enable g to see every occurrence highlighted and listed. The g flag is enabled by default in this tool.
How do I match email addresses with regex?
Click the Email quick-pattern button to use a standard email regex pattern. The pattern [^\s@]+@[^\s@]+\.[^\s@]+ matches most common email formats. Note that fully RFC-compliant email matching requires a much more complex pattern. For real-world use, validate email by sending a confirmation message rather than relying solely on regex.
What is the difference between .* and .+?
.* matches zero or more of any character, meaning the preceding element is optional and the match can be empty. .+ matches one or more of any character, requiring at least one character to be present. Use .* when empty matches are acceptable; use .+ when you need at least one character. Both are greedy by default — add ? to make them lazy (non-greedy): .*? or .+?