toolulu Easy · Ready · Everywhere

Your connection

…

Local time
—
Time zone
—
Reverse DNS
—
System
—
Browser
—
LogligentMonitoring & Security Intelligence Understand what your
servers are telling youAlready been hacked? Yes? No? Don't know?
Logligent detects and responds.
Sign up free

Run it. Get results.

Regex Tester

Free
Test a regex as you type: matches highlighted, groups listed, replace preview and the pattern explained in plain words. Free, in your browser.
tooluluEasy · Ready · Everywhere

Use your phone as the camera

Scan this code with your phone's camera, then take a photo of the text. Its words appear here, ready to translate.

Waiting for your phone…

The code works for 15 minutes, for up to 10 photos. Photos are read, then thrown away.

Popular

Pick your tool

toolulu Easy · Ready · Everywhere

156 tools

Open this tool?

About the Regex Tester

A free regex tester: type a regular expression and some text, and see every match highlighted as you type, with each match's position and groups (named groups too), a replace preview ($1, $<name>) and the pattern explained piece by piece in plain words. Start from ready patterns for emails, URLs, Philippine mobile numbers, dates and IP addresses. It uses JavaScript regular expressions, in your browser.

How to use it

  1. Type the pattern between the slashes, and the flags (g, i, m, s, u, y) after them.
  2. Paste the text to test: the matches are highlighted at once.
  3. Read the matches and groups, try a replacement, and check what each part of the pattern means.

Questions

Which regex flavour is this?

JavaScript (ECMAScript). The basics (classes, groups, quantifiers, anchors) work the same in Python, PHP (PCRE), Java and .NET; lookbehind and named groups are written slightly differently in some.

Why does it find only one match?

Turn on the g (global) flag to find every match.

How do I match a dot or a bracket?

Put a backslash before it: \. matches a dot, \( a bracket. Without it, . means "any character".

What does "stopped after a second" mean?

The pattern backtracked too much (for example (a+)+ on a long text). It is stopped so the page doesn't freeze; make the repeats less nested or more specific.

How do I use groups in the replacement?

$1, $2… insert numbered groups, $<name> a named group and $& the whole match.

Is my text sent anywhere?

No: the pattern runs in your browser only.

Did you know?

Two circles and an arrow: 1951

Kleene's regular sets

The logician Stephen Kleene spent the summer of 1951 at the RAND Corporation, where he found a key characterisation of finite automata: the "regular sets" behind regular expressions.

Source: MacTutor (University of St Andrews)

A screen: s/a*b/x/

The first regex editor

Ken Thompson's QED editor was the first to let users search and substitute with regular expressions; before that, editors could search only for a literal string.

Source: Dennis Ritchie (Bell Labs)

A star

ed kept only the star

The "standard Unix editor" ed, first written by Ken Thompson, cut regular expressions down to the * operator: no alternation and no parentheses.

Source: Dennis Ritchie (Bell Labs)

PCRE: 1997

Perl's style everywhere

The PCRE library, first released in 1997, matches with the same syntax and meaning as Perl 5, and is used by Apache, PHP, KDE, Postfix and Nmap.

Source: PCRE

Named groups and lookbehind

JavaScript's 2018 upgrade

ECMAScript 2018 added four regular expression features to JavaScript: the dotAll flag, named capture groups, Unicode property escapes and look-behind assertions.

Source: TC39 (ECMAScript 2018)

.*.*=.* at 100% CPU

One regex, 27 minutes

On 2 July 2019 a poorly written regular expression backtracked so much that it used up Cloudflare's CPUs, taking its service down for 27 minutes.

Source: Cloudflare

Tips for Regular Expressions

  1. Escape special characters

    Match a real . * + ? by putting \ before it.

  2. Anchor it

    ^ and $ make the pattern match the whole text.

  3. Find them all

    Turn on g to find every match, not just the first.

  4. Lazy repeats

    Add ? after * or + to take as little as possible.

  5. Capture with groups

    ( ) keeps a part: use it as $1 in replacements.

  6. Name your groups

    (?<year>\d{4}) is easier to read than $1.

  7. Avoid nested repeats

    Patterns like (a+)+ can take forever on long text.

  8. Test both ways

    Test text that should match and text that shouldn't.

Advertisements

tooluluEasy · Ready · Everywhere

Advertisements

AcesFive