Skip to content
animorio
IT
Back to the library

Regex tester

Text, HoverGSAP, CSS onlyMediumCompressed weight: Demo 7.0 KBGSAP 28 KBFreeDownload the zip

The regular expression tester of a developer tool: the pattern is typed in a real field and the matches light up in the text at every key, from thirty-five digits down to three dates. Each group has its colour in the pattern, in the text and in the chips below, which say what it captured in the match being read.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Regex tester" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Regex tester</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- a regular expression tester: the pattern is a real input, the matches light up in the sample text
         as it is typed, and each capture group has its colour in the pattern, in the text and in the chips -->
    <section class="rx" data-rx aria-label="Regular expression tester">
      <header class="rx__head">
        <span class="rx__name">Pattern</span>
        <span class="rx__roll rx__status" aria-live="polite"><span data-status></span></span>
      </header>
      <label class="rx__field" data-field>
        <span class="rx__slash" aria-hidden="true">/</span>
        <span class="rx__box">
          <span class="rx__mirror" data-mirror aria-hidden="true"></span>
          <input class="rx__input" data-input type="text" aria-label="Regular expression" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false">
        </span>
        <span class="rx__slash" aria-hidden="true">/g</span>
      </label>
      <div class="rx__text" data-text aria-label="Sample text"></div>
      <div class="rx__groups" data-groups aria-label="Capture groups of the match being read"></div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

16 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Regex tester” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On black, a dark card: “Pattern”, the count pill, a field between two slashes holding the pattern, four lines of sample text (an order, an invoice, a refund, a phone number) and the group chips at the bottom. The demo types the pattern in pieces, like an editor that closes brackets for you, so every step is a valid pattern: with “(\d)” all thirty-five digits light up, one after the other; with “{4}” the five four-digit numbers remain; with the hyphen only the three years of the dates, and piece by piece the highlight stretches to the three whole dates. The count on top rolls at every step. Each bracketed group has a colour, amber, cyan and violet, the same in the pattern, in the text and in the chips “$1”, “$2”, “$3”, which show year, month and day of the match being read. Hover another date and the lime ring moves while the chip values roll; hover a chip and that group stays lit everywhere while the rest steps back. The field is real: type any pattern, and one left unfinished turns the border red without wiping the last result.

How it works

The engine is the browser’s

The pattern goes to new RegExp with the g and d flags inside a try: if it is valid the matches are found, if not the card flags the error and keeps the previous result. The d flag gives each group’s indices, needed to colour them in the text.

The field has a mirror

An input cannot have letters of different colours: its text is transparent and under it lies a copy, character by character, coloured by the group it belongs to. A small function reads the pattern and counts the capturing brackets.

Only the new lights up

At every key the text is rebuilt with one mark per match. Those already there, same start and same end, do not replay the animation; new ones come in one after the other with the background widening from the left.

Reading a group

A class on the card dims everything except elements carrying the chosen group’s number: the same attribute sits in the pattern’s mirror and in the text, so one querySelectorAll is enough.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#c8f55aThe colour of the caret, the count and the ring around the match being read.
SPEEDscript.js1How fast the demo types the pattern: 0.5 = slow, 2 = fast.
POPscript.js1How much the highlight swells when a match lights up: 0 = none, 2 = a lot.
LOOPscript.jstrueLeft alone, the demo types the pattern piece by piece and then reads the groups.

Try them in the Playground

When to use it

On the page of a developer tool, in a language’s documentation, in an online editor, in the filter panel of an app that searches logs. The same coloured mirror under a field suits a formula, a query or a command.

On phones

The same card, as wide as the screen, with slightly smaller type so pattern and lines fit. You type with the phone keyboard; a date or a chip is read by tapping it.

With reduced motion

The pattern is already written and the three dates already highlighted; matches change without animation and values without rolling. The demo does not move by itself.

Pitfalls

  • Order, invoice, dates and phone number are made up.
  • A pattern that can match nothing (like “()” or “\d*”) would lock the exec loop forever: when the match is empty, lastIndex is advanced by hand and the match skipped.
  • The d flag is missing in older browsers: the second attempt uses g alone and groups stay uncoloured in the text, but the rest works.
  • The mirror does not scroll by itself when the pattern is longer than the field: it has to follow the input’s scrollLeft on every scroll event.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.0 KB; the libraries: GSAP 28 KB.

Testing

Tested on 20 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations