Regular expression tester

Type a regular expression and some test text: you will instantly see the highlighted matches, the captured groups and the result of a replacement. It uses your browser's JavaScript regex engine.

Regular expression

/ /g

Highlighted matches

#PositionMatchGroups

Replace

Use $1, $2… for groups, $<name> for named groups and $& for the whole match.

What is a regular expression?

A regular expression (regex or regexp) is a pattern that describes a set of text strings. It is used to search, validate and replace text: checking whether an email address is well formed, extracting every IP from a log or changing the format of some dates.

Quick cheat sheet

. any character · \d digit · \w letter, digit or _ · \s whitespace · \b word boundary · ^ and $ start and end · [abc] one of those characters · [^abc] anything except those · a|b a or b.

Quantifiers: * 0 or more, + 1 or more, ? 0 or 1, {n,m} between n and m times; add ? to make them lazy (.*?). Groups: (…) capturing, (?:…) non-capturing, (?<name>…) named, (?=…) and (?!…) positive and negative lookahead.

Differences between languages

The basic syntax is shared by almost every language (JavaScript, PHP/PCRE, Python, Java, .NET), but advanced features such as inline modifiers, Unicode classes or lookbehind differ. This page uses the JavaScript engine, so the result is exactly what you will get in the browser or in Node.js.