How to use it
- Pick an example to start from, or type your own pattern. Leave off the
/marks at each end. - Tick the flags you need. Tick g to find every match and not only the first.
- Paste the text you want to search in the Test text box.
- Read the result. Matches are highlighted in the text. The table lists each match, where it starts, and its groups.
- To test a replacement, type it in the Replace box. The text after the replacement shows below.
Everything updates as you type. Your pattern and your text stay in your browser.
The flags
- g finds all matches. Without it, the search stops at the first one.
- i ignores upper and lower case.
- m makes
^and$match at the start and end of each line. - s lets the dot match a line break.
- u treats the text as full Unicode, so an emoji counts as one character.
Groups and replacements
Round brackets make a group. The tool shows the text each group caught as $1, $2 and so on. In the replace box, write $1 to put that text back. A named group, written (?<year>\d{4}), is easier to read. Use it in the replacement as $<year>. Write $& for the whole match.
The index in the table counts characters from the start of the text. The first character has index 0.
The examples
The list has patterns that Windows admins use often: an IPv4 address, a GUID, a computer name that follows a site-type-number naming rule, an email address, and the timestamp at the start of a log line. Each one loads sample text that shows what matches and what does not. Change the pattern to fit your own naming rule or log format.
Which regex flavor is this?
The tool uses the regular expression engine of your browser, which is the JavaScript flavor. Most patterns also work in PowerShell and .NET. A few things differ:
- PowerShell
-matchignores case unless you use-cmatch. JavaScript needs the i flag. - .NET writes a named group in a replacement as
${name}. JavaScript writes$<name>. - .NET sets options inside the pattern with
(?i). JavaScript does not accept that form, so use the flags.
Test the final pattern in the system that will run it.
Questions
Why do I get only one match?
The g flag is off. Without it, a JavaScript regular expression stops after the first match. Tick g to see them all.
Why does the page slow down with some patterns?
Some patterns make the engine try a huge number of paths. Nested repeats such as (a+)+ are the usual cause. Rewrite the pattern so that only one part can match each character, or test with a shorter text.
How do I match a real dot or bracket?
Put a backslash in front of it. \. matches a dot and \( matches a bracket. Without the backslash, a dot matches any character.