StoicBuilder

HandbookI the LudusRegular expressions

Ithe Ludus, Read code

Regular expressions

1 min readUpdated 28 November

In plain words

A regular expression is a short pattern of symbols that describes what text should look like, so code can search, check or clean it.

Where you see it

A dense run of symbols between two forward slashes, like /^[^\s@]+@[^\s@]+$/. Your agent writes one to check emails on a signup form or to pull hashtags out of a Chirp post.

src/lib/hashtags.tsbrowser
const text = "Launch day for #quill and #buildinpublic"; // a #, then one or more letters, digits or underscoresconst tags = text.match(/#\w+/g);// ["#quill", "#buildinpublic"]
The g at the end means every match, not only the first.

What goes wrong

  1. An email check that turns away real people

    Strict patterns reject valid addresses with a + or an unusual domain, like maya+quill@studio.design. Check for an @, then confirm by sending an email.

  2. Missing ^ and $

    Without them the pattern only has to match somewhere inside the text, so a digits-only check passes "abc123xyz".

    /\d+/.test("abc123xyz") // true
  3. Trusting a pattern nobody can read

    If no one on the project can explain a regex, no one can tell when it's wrong. Make the agent break it down and show examples that pass and fail.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Explain this regular expression piece by piece in plain English, then list five inputs it accepts and five it rejects, including edge cases. If a built-in check or a small, well-known library does the job more clearly, use that instead.

Quick check

Sign in to earn +10 XP for it

A phone field uses /\d+/ to allow digits only, yet "call me 0712" passes. What's missing from the pattern?

Got a prompt that touches regular expressions?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.