About Regex Tester
A regular expression is a pattern that describes text, used to validate emails and phone numbers, extract values from logs, and find and replace text in editors and code. Writing one correctly usually takes a few tries, so it helps to see the matches immediately.
Put the pattern on the first line and the text to search on the lines below. The tool lists every match with its text, its position and its capture groups. By default the g and m flags are on. To set your own flags, write the first line as /pattern/flags, for example /hello/gi. The tool uses the JavaScript regular expression engine in your browser.
How to use Regex Tester
- Type the pattern on line 1, either plain or as /pattern/flags.
- Type or paste the text to test on the lines below it.
- Click Run Tool to list the matches, their index and capture groups. If nothing matches, the tool says so.
Example
Input
/\b[\w.]+@[\w.]+\.\w+\b/g Write to hello@example.com or sales@nhplearning.com today. Not an address: hello@
Output
[
{
"match": "hello@example.com",
"index": 9,
"groups": []
},
{
"match": "sales@nhplearning.com",
"index": 30,
"groups": []
}
]Common uses
- Building a pattern for form validation before putting it in JavaScript or PHP.
- Extracting email addresses, IDs or dates from a block of text.
- Debugging why a pattern in your code matches too much or too little.
Privacy and safety
This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.
Frequently asked questions
What do \d, \w and \s mean?
\d matches a digit, \w matches a letter, digit or underscore, and \s matches whitespace. Capital versions such as \D match the opposite. A dot matches any character except a new line, and + means one or more.
Will my pattern behave the same in PHP?
Mostly, but not always. PHP uses PCRE, which differs from JavaScript in areas such as named group syntax and some advanced features. Always test the final pattern in PHP too.
How do I match special characters literally?
Escape them with a backslash. To match a dot write \. and to match a question mark write \?