Utvikling · verktøy

Regex-tester

Skriv inn et mønster, velg flagg og test det umiddelbart mot teksten.

Kjøres i nettleseren. Ingen opplasting.

Regular expressions run locally in your browser.

Matches0
No matches yet.

Om verktøyet

Regex-tester sem complicação.

Bruk verktøyet til å feilsøke mønstre før du legger dem inn i JavaScript, en regel for skjemavalidering eller et søk. Alt kjøres lokalt.

Veiledning

Slik bruker du Regex-tester

Type a pattern, add flags and paste some text, and this page lists every piece of the text that matches. It uses the regular expression engine that is built into your browser, which is the JavaScript one, so a pattern that works here behaves the same in JavaScript code. Other languages such as Python, PHP or Java have their own differences. The page lists matches as text; it does not highlight them or explain the pattern.

Slik gjør du

  1. Type your pattern in the Pattern box, without the slashes. For example, \b\w+@\w+\.com\b looks for simple email addresses.
  2. Check the Flags box. It starts with gi, which means all matches and ignore case. Delete or change letters to suit your test.
  3. Paste the text you want to search into the large Text to test box.
  4. Press Test expression. The Matches number shows how many were found, and each match is listed below.
  5. If you see an error, fix the pattern or flags. Press Clear to empty the boxes and set the flags back to gi.

Eksempler

Find every simple email address

Du skriver inn
Mønster
\b\w+@\w+\.com\b
Flagg
g
Tekst
Mail ana@example.com or bob@test.com today
Du får
Treff
2
Liste
ana@example.com; bob@test.com

The g flag keeps looking after the first hit, so both addresses are found. This pattern is deliberately simple and will miss many valid addresses.

Kjørt med verktøyets egen kode.

Groups with and without the g flag

Du skriver inn
Mønster
(\d{4})-(\d{2})-(\d{2})
Flagg
Tekst
Due 2026-03-14 and 2026-04-01
Du får
Treff
1
Første treff
2026-03-14
Detaljer
Indeks: 4; Grupper: 2026; 03; 14

With no g flag, only the first match is returned. The page adds the start position and the three captured groups under it. Add g to the flags and the count becomes 2.

Kjørt med verktøyets egen kode.

Greedy against lazy

Du skriver inn
Mønstre
<.+>; <.+?>
Flagg
g
Tekst
<b>x</b>
Du får
Grådig
<b>x</b>
Ikke-grådig
<b>; </b>

A plain + grabs as much as it can, so one match covers the whole string. Adding ? after it makes it stop at the first possible end, which gives the two tags.

Kjørt med verktøyets egen kode.

A pattern that can match nothing

Du skriver inn
Mønster
a*
Flagg
g
Tekst
baab
Du får
Treff
4
Liste
(empty); aa; (empty); (empty)

The star allows zero letters. So an empty match is found before the b, then aa, then empty matches before the last b and at the very end. Empty matches show as blank lines.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Try a pattern before pasting it into JavaScript code, a form check or a search-and-replace.
  • Pull dates, numbers or codes out of a pasted log, list or document and count them.
  • Learn what a flag such as i, m, s or u changes by switching it on and off on the same text.
  • Check why a pattern matches too much, such as the greedy tag example, by comparing small variations.
  • Test a pattern on a few lines of sample text without writing a script.

Begrensninger

  • It uses your browser's JavaScript engine only. Syntax from other languages, such as (?i) at the start or (?P<name>...), is rejected as an invalid group.
  • A test that runs for more than 1 second is stopped, and the page asks you to simplify the expression. Patterns with heavy backtracking can trigger this.
  • The page lists the matched text, and the start position is shown only for matches that have capture groups. It does not highlight matches inside your text.
  • There is no replace mode and no step-by-step explanation of what each part of the pattern does.
  • Error messages for a bad pattern or flag come from the browser itself, so the wording differs between browsers.

Tips

  • Build the pattern in small pieces. Add one part, test it, then add the next, so you know which part broke it.
  • Write a few lines that should match and a few that should not, and test them together.
  • Remember that the dot does not match a line break unless you turn on the s flag.
  • Use ^ and $ with the m flag when you want to match at the start and end of each line, not of the whole text.

Kilder

Vanlige spørsmål

Sobre Regex-tester.

Which regular expression engine does this use?

The one built into your browser, which is the JavaScript engine that follows the ECMAScript specification. The pattern is run with the standard RegExp object, so results match what the same pattern does in JavaScript code in that browser.

Do I type the slashes around the pattern?

No. Type only the pattern in the Pattern box and the flags in the Flags box. In JavaScript code you would write /pattern/flags, but here the two parts are kept apart, so slashes in the box are treated as characters to match.

Which flags can I use?

Any flags your browser's JavaScript supports, such as g, i, m, s, u and y. An unknown letter gives an error. The default is gi, and the Clear button restores it. MDN lists every flag and what it does.

Why do I get only one match?

You probably left out the g flag. Without it the search stops at the first match. Add g to the flags box and press Test expression again to list them all.

Will my pattern work in Python, PHP or Java?

Often, but not always. Basic parts such as classes, groups and quantifiers are shared, yet details differ. Python writes named groups as (?P<name>...), which JavaScript rejects, and inline flags like (?i) do not work here. Test in the language you will use.

Why did I see a message about taking too long?

The test runs in a background worker with a 1 second limit. Some patterns try an enormous number of paths on certain text, known as catastrophic backtracking. The page stops the test and asks you to simplify it.

How do I see my capture groups?

When a match contains capture groups, the page prints a line below it with the start index and the list of groups. Named groups, such as (?<year>\d{4}), are shown by name as well.

Why are there blank lines in my results?

A pattern like a* can match zero characters, and each empty match is counted and listed as a blank line. The count at the top includes them. Use a+ if you want at least one character.

Is my text sent to a server?

No. The pattern and text are tested in your browser, in a worker on your own device. Nothing is uploaded. Still, avoid pasting real passwords or private data into any test box on a shared computer.

Hvordan bruker du Regex-tester?

Skriv inn et mønster, velg flagg og test det umiddelbart mot teksten.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.