Technology Apr 15, 2026 · 1 min read

Regex That Actually Works (Copy-Paste Ready Examples)

You paste a regex. It doesn’t work. You change one character. Now it works. You have no idea why. At some point you just accept it. Regex is not something you fully understand. It’s something you negotiate with. Typical workflow: google "regex email" copy something scary-looking pa...

DE
DEV Community
by Andrew Rozumny
Regex That Actually Works (Copy-Paste Ready Examples)

You paste a regex.

It doesn’t work.

You change one character.

Now it works.

You have no idea why.

At some point you just accept it.

Regex is not something you fully understand.

It’s something you negotiate with.

Typical workflow:

  • google "regex email"
  • copy something scary-looking
  • paste
  • test
  • slightly panic
  • tweak random symbol
  • it works
  • never touch it again

Here are a few patterns that actually come up all the time.

Email (good enough, not perfect):

^[^\s@]+@[^\s@]+\.[^\s@]+$

URL (basic, but works in most cases):

https?:\/\/[^\s]+

Only numbers:

^\d+$

Remove extra spaces:

\s+

The problem with regex is not writing it.

It’s understanding it later.

You come back after a week and think:

“what is this even matching?”

Most bugs are stupid:

  • forgot to escape something
  • used greedy match by accident
  • missed boundaries

Nothing complex.

Just painful.

What helped me:

stop trying to be clever.

Start simple. Then expand.

Also, use a tester.

Seriously.

👉 https://tooldock.org/tools/regex-tester

Paste → tweak → see what’s happening.

Way faster than guessing.

If you have one regex you keep reusing — drop it below.

I’m pretty sure we’re all sharing the same 5 patterns anyway.

DE
Source

This article was originally published by DEV Community and written by Andrew Rozumny.

Read original article on DEV Community
Back to Discover

Reading List