Regular Expression
Flags:
Test String
Matches
How to Use the Regex Tester & Examples
This tool allows you to test JavaScript-compatible regular expressions (regex) against any text string in real-time. Matches found will be highlighted in the "Matches" area above.
Steps:
- Enter your regular expression pattern in the "Regular Expression" input field. Do not include the starting/ending slashes (`/`) or flags here; they are handled by the checkboxes.
- Select the desired flags (like `g` for global search, `i` for case-insensitive) using the checkboxes.
- Paste or type the text you want to test into the "Test String" area.
- Matches will automatically appear highlighted in the "Matches" output area as you type.
- If your regex pattern is invalid, an error message will be shown in the "Matches" area.
Common Flags:
g
(Global): Find all matches rather than stopping after the first match.i
(Ignore Case): Makes the matching case-insensitive.m
(Multiline): Allows start (^
) and end ($
) anchors to match the start/end of lines (not just the entire string).s
(Dotall): Allows the dot (.
) metacharacter to match newline characters (\n
).u
(Unicode): Enables full Unicode support.y
(Sticky): Requires the match to occur only at the `lastIndex` position.
Example 1: Matching Email Addresses
Regex Pattern:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Flags: g
| Test String:
Contact us at support@example.com or sales.info@company.co.uk. Invalid: user@localhost
Result: Highlights support@example.com
and sales.info@company.co.uk
.
Example 2: Extracting Hashtags
Regex Pattern:
#\w+
Flags: g
| Test String:
Loving the #weekend vibes! #coding #fun
Result: Highlights #weekend
, #coding
, and #fun
.
Example 3: Case-Insensitive Matching
Regex Pattern:
error
Flags: g
, i
| Test String:
An Error occurred. Please report the ERROR. No error here.
Result: Highlights Error
, ERROR
, and error
.