# Regex Debugger — Examples

> Runnable walkthroughs with the Regex Debugger: match emails, read capture groups, named groups, try the flags, and test lookaround.

Source: https://www.jpkc.com/db/en/tools/regex/examples/

Back to the overview: [Regex Debugger](https://www.jpkc.com/db/en/tools/regex/) · Open the tool: [www.jpkc.com/tools/regex/](https://www.jpkc.com/tools/regex/)

The [manual](https://www.jpkc.com/db/en/tools/regex/manual/) describes every field and flag. This page complements it with **concrete walkthroughs**: real patterns that run in the JavaScript engine, each with matching test text and an explanation of what you'll see in the match display. You can type all examples directly — pattern into the **Pattern** field, text into the **Test String** field, flags as noted.

## Example 1: Match email addresses

The classic — find all email addresses in a block of text.

- **Pattern:** `[\w.+-]+@[\w-]+\.[\w.-]+`
- **Flags:** `g`
- **Test String:**

```
Write to info@example.com or to support@mail.example.org.
Spam to: nope@.com (invalid).
```

With `g` on, **Matches** lists both valid addresses as match 1 and 2, each with `pos X-Y`, and highlights them in color in the text. The invalid `nope@.com` is (depending on the pattern) not matched or only partly matched — which is exactly what the debugger is for: you see at once where your pattern is too lax or too strict. Toggle `g` off and watch the list shrink to **only the first match**.

## Example 2: Read capture groups — break apart a date

Capture groups grab parts of a match separately. Here you break a date into day, month, and year.

- **Pattern:** `(\d{2})\.(\d{2})\.(\d{4})`
- **Flags:** `g`
- **Test String:**

```
Meeting on 19.06.2026, deadline 30.06.2026.
```

Each match shows the numbered groups below the match value: `Group 1:` the day, `Group 2:` the month, `Group 3:` the year. That's how you check whether your parentheses grab the right pieces before you process them in code via `match[1]`, `match[2]`, and so on. Note: the dots in the pattern are escaped as `\.` — a bare `.` would match any character.

## Example 3: Named capture groups

Instead of remembering `Group 1/2/3`, give the groups names. This is also the tool's starting example.

- **Pattern:** `(?<day>\d{2})\.(?<month>\d{2})\.(?<year>\d{4})`
- **Flags:** `g`
- **Test String:**

```
Meeting on 19.06.2026.
```

In **Matches**, the named groups now appear in addition to the numbered ones as `<day>:`, `<month>:`, and `<year>:` with their values. In code you later read them via `match.groups.day` — more readable and more robust than relying on parenthesis order. Type the tool's starting example `(?<word>\w+)` and you'll see the same principle on individual words.

## Example 4: Try the flags — i, m, and s

The same input, three flags, three results. Take this multi-line text:

```
Error: file not found
error: access denied
OK: all good
```

1. **`i` (case insensitive).** Pattern `error`, only `g`: matches just the lowercase line. Add `i` — now **both** "Error" lines match, regardless of case.
2. **`m` (multiline).** Pattern `^error`. Without `m`, the anchor `^` only matches at the very start of the string — the second line isn't caught. With `m` (and `i`), `^` matches **every line start**, and the "error" line in the middle is matched.
3. **`s` (dotall).** Pattern `Error.*denied` with `i`. Without `s`, `.` matches no newline, so the match never forms. With `s`, `.` may skip over newlines — the expression now spans the line break.

This gives you a feel for the fact that the flags aren't cosmetic; they change the semantics of the pattern.

## Example 5: Lookaround — check context without capturing it

Lookahead and lookbehind check the surroundings of a match without making them part of the match itself. JavaScript handles both directions.

- **Pattern (lookbehind):** `(?<=\$\s?)\d+(?:\.\d{2})?`
- **Flags:** `g`
- **Test String:**

```
Price: $ 19.99 — down from $ 29.99. Item number 12345.
```

The positive lookbehind `(?<=\$\s?)` requires a dollar sign (optionally with a space) before the number — but **only the number** is matched. So you find amounts without picking up the `12345` that has no dollar prefix. In the match list you'll see only `19.99` and `29.99`, not the `$`.

## Example 6: Invalid pattern and zero-length matches

Two instructive edge cases.

- **Invalid pattern:** Type `(unbalanced` into the Pattern field. No `RegExp` can be built — instead of a match list, the engine's **original error message** appears and the counter reads **"Error"**. Close the parenthesis (`(unbalanced)`) and the error disappears immediately.
- **Zero-length match:** Pattern `\b`, flags `g`, any text. A word boundary has no width — it matches "between" characters. The tool counts these matches correctly (each with `pos X-X`, start equal to end) without getting stuck in the infinite loop a global zero-length match would otherwise trigger.

---

Going deeper: the [overview](https://www.jpkc.com/db/en/tools/regex/) for the big picture, the [manual](https://www.jpkc.com/db/en/tools/regex/manual/) for every feature in detail, and the [tips & tricks](https://www.jpkc.com/db/en/tools/regex/tips/) for pitfalls and engine quirks. You can try all of it directly in the [tool](https://www.jpkc.com/tools/regex/).

