OmniFeed Search

Regex tester

The tester uses your browser's own JavaScript engine, so your pattern follows JavaScript's rules, which differ from PCRE's and Python's in places. You'll see up to 1,000 matches, each with its groups. It runs in your browser; nothing you enter is uploaded.

Flags

    What the flags do

    Every current browser supports all six, along with named groups and lookbehind, which arrived with s in ES2018. If your text has emoji or letters outside English, turn on u. The MDN regular expressions guide covers the full syntax.

    Reading the matches

    The index is where the match starts, counting from 0 in UTF-16 code units. It's the same number match.index gives you in code. Most characters are one unit, but an emoji such as 😀 is two, so every index after it is one higher than the number of characters you see.

    Groups are numbered by their opening parenthesis, left to right, and the tester also lists a named group such as (?<year>…) under its name. With the example pattern, the first match is 2024-03-15 at index 9. Group 1, named year, is 2024; group 2, named month, is 03; and group 3 is 15.

    A group that took no part in the match, such as the second group of (a)|(b) when the text is "a", shows as "(no match)". A group that matched an empty string shows as "(empty)" instead. Without the g flag, the tester lists only the first match, the one exec() would return.

    Empty matches

    Patterns such as a*, ^, or \b can match zero characters. If the tester searched again from the same spot, it would find the same empty match forever. So after an empty match it moves on one position, or one whole code point with the u flag. String.prototype.matchAll does the same, so you get exactly the matches it would return: a* against "baac" gives an empty match at 0, aa at 1, and then empty matches at 3 and 4.

    Pitfalls

    Using the pattern in code

    const re = /(?<year>\d{4})-(?<month>\d{2})-(\d{2})/g
    for (const m of text.matchAll(re)) {
      console.log(m.index, m[0], m.groups.year)
    }
    text.replace(re, '$<month>/$3/$<year>') // "Released 03/15/2024, …"

    matchAll needs the g flag and throws an error without it. If you only need to know whether the text matches, use re.test(text). But with g or y, the regex remembers where it stopped in re.lastIndex, so calling test twice on the same text can give different answers.

    More in text

    Other tools