Skip to content
HNarzędzia
en
Categories

Regex tester - test JavaScript regular expressions online

Type a pattern and a test string to see every match highlighted, with a table of capture groups and a live replace preview. Matching runs in a Web Worker with a time limit, so a runaway pattern is stopped instead of freezing the page.

  • Free
  • No sign-up
  • Private
  • Runs locally
Flags

Pattern library (Poland)

Click to insert the pattern and a sample text.

Email address
/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g

Local part, @, a domain with at least one dot and a TLD of 2+ letters. An approximation: the full RFC 5322 grammar is far more complex.

Polish postal code
/\b\d{2}-\d{3}\b/g

Two digits, a hyphen, three digits (00-950). \b enforces word boundaries. It does not check that the code actually exists.

PESEL (format)
/\b\d{11}\b/g

Exactly 11 digits (the Polish national ID number). Checks the format only, not the checksum or date of birth. Use a PESEL validator for that.

NIP tax ID (format)
/\b(?:PL\s?)?(?:\d{3}-\d{3}-\d{2}-\d{2}|\d{3}-\d{2}-\d{2}-\d{3}|\d{10})\b/g

Polish tax ID as 123-456-78-90, 123-45-67-890 or 10 digits, optionally prefixed with PL (EU VAT). Does not verify the checksum.

Polish phone number
/(?<!\d)(?:(?:\+|00)48[ -]?)?(?:\d{3}([ -]?)\d{3}\1\d{3}|\d{2}[ -]?\d{3}[ -]?\d{2}[ -]?\d{2})(?!\d)/g

9 digits (mobile 600 123 456 or landline 22 123 45 67), optionally with +48 or 0048. Separators are spaces or hyphens. In mobile numbers they must be consistent (backreference \1).

URL (http/https)
/https?:\/\/(?:[a-z0-9-]+\.)+[a-z]{2,}(?::\d{2,5})?(?:[\/?#][^\s]*)?/gi

http(s)://, a domain with a TLD, optional port, path, query and fragment (up to the first space). The i flag handles uppercase.

Date DD.MM.YYYY
/\b(?:0[1-9]|[12]\d|3[01])\.(?:0[1-9]|1[0-2])\.\d{4}\b/g

Day 01-31, month 01-12, four-digit year, the format used in Poland and much of Europe. Checks the format only; it does not know that 31.02 does not exist.

Polish IBAN
/\bPL\s?\d{2}(?:\s?\d{4}){6}\b/g

PL + 2 check digits + 24 digits (6 groups of 4), spaces optional. Does not verify the mod-97 checksum.

How to test a regular expression

  1. 1.

    Enter the pattern

    Type the expression without slashes, e.g. (\d{4})-(\d{2}), and switch on the flags you need (g, i, m, s, u, y, d).

  2. 2.

    Paste the test text

    Matches are highlighted as you type, and the table lists each match with its position and capture groups.

  3. 3.

    Preview a replacement

    Enter a replacement such as $2-$1 or $<name> to see the result of String.replace().

  4. 4.

    Start from a ready pattern

    Use the pattern library for emails, URLs, dates and common Polish formats as a starting point.

JavaScript regex flags

FlagNameEffect
gglobalfind all matches, not just the first
iignoreCasecase-insensitive matching
mmultiline^ and $ match at the start and end of every line
sdotAllthe dot also matches newline characters
uunicodefull Unicode support, e.g. \p{L} for any letter
ystickymatch only at lastIndex
dhasIndicesreturn start and end positions of groups

In JavaScript \w and \b only cover ASCII letters, so “é”, “ü” or “ł” count as non-word characters. To match words in any language, use the u flag with \p{L}, for example [\p{L}\p{M}]+.

Capture groups, named groups and replacements

Parentheses ( ) create capture groups numbered from 1. A named group looks like (?<name>…). In the replacement you refer to them as $1 or $<name>, while $& inserts the whole match.

For example, the pattern (?<year>\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$<year> turns “2026-03-15” into “15/03/2026”. A non-capturing group is written (?:…), a lookahead (?=…), a negative lookahead (?!…) and a lookbehind (?<=…). The results table shows every group for every match, with “-” for groups that did not participate.

Pattern library

The library at the bottom of the tool contains tested patterns for an email address, an http(s) URL and a DD.MM.YYYY date, plus formats you meet when dealing with Polish data: postal code (\d{2}-\d{3}), PESEL national ID (11 digits), NIP tax ID (with or without hyphens and the PL prefix), phone numbers with +48 and the Polish IBAN. Each one comes with a sample text, and every pattern is covered by automated tests with valid and invalid examples.

A regex checks only the format. It cannot compute checksums (PESEL, NIP, IBAN mod 97), and it does not know that 31.02 does not exist. For real validation, combine the regex with code, or use a dedicated validator such as the IBAN validator.

Catastrophic backtracking (ReDoS)

Some patterns, such as (a+)+$ run against “aaaaaaaaaaaaaaaaaaaaaaaaaaab”, make the number of matching attempts grow exponentially and can hang the browser or a server. ReDoS attacks exploit exactly this. This tester runs matching in a separate thread (a Web Worker) with a 2-second limit. When the limit is exceeded, the worker is terminated and you see a warning instead of a frozen tab. Avoid nested quantifiers and overlapping alternatives such as (a|a)*, and prefer specific character classes like [^"]* over .*.

Frequently asked questions

Which regex engine does the tester use?

+
Your browser’s built-in RegExp engine. It follows the ECMAScript standard, so the syntax is the same as in Node.js and in scripts on web pages. It differs slightly from PCRE (PHP) and Python: for example there are no possessive quantifiers or atomic groups.

Why does \w not match accented letters?

+
In JavaScript \w means only [A-Za-z0-9_]. Turn on the u flag and use \p{L} (any letter) instead, for example [\p{L}]+ to match words such as “café” or “Łódź”.

Why does my pattern freeze or time out?

+
Usually because of catastrophic backtracking: the number of attempts grows exponentially with the text length. Simplify the pattern, remove nested quantifiers or use more specific character classes.

How do I use named groups in the replacement?

+
Define the group as (?…) and use $ in the replacement field. Numbered groups work as $1, $2 and so on, and $& inserts the whole match.

Can a regex validate an email address completely?

+
Not practically. The full RFC 5322 grammar is huge. The library pattern catches typical typos; to be sure an address works, send a confirmation email.

Is my text sent to a server?

+
No. All matching happens locally in your browser.

Updated: