/ /
Enter a pattern and test string above
Common Patterns — click to use

How to Use

1
Enter your pattern. Type your regex in the pattern field (without surrounding slashes). Common patterns are available as quick-copy buttons at the bottom.
2
Set flags. Click the flag buttons to toggle options: g (global — find all matches), i (case insensitive), m (multiline), s (dotAll — dot matches newlines).
3
Enter test string. Paste the string you want to test against. Matches are highlighted in yellow in the display below and listed with their positions.
4
Read the results. The match count bar shows how many matches were found. The match list shows each match value and its character position in the string.

Regex Flags Explained

g — global: find all matches (not just the first) i — case insensitive: A matches a and A m — multiline: ^ and $ match start/end of each line s — dotAll: . matches newline characters (\n)

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 .+?

Get fresh reads straight to your inbox

Get notified when we publish new articles. Unsubscribe anytime.