tallge

Tools / Regex tester

JavaScript regular expression tester

This is the JavaScript flavour, run by the engine in your browser. Patterns that behave the same in PCRE or Python usually behave the same here, but lookbehind, named groups and Unicode classes differ in the details.

Flags
Up to 50,000 characters

Matches

Matches and groups (first 200)
Use $1, $<name>, $& for the whole match, $$ for a dollar sign

Examples:

Freezing and how it is avoided

A backtracking engine can take exponential time on patterns like (a+)+$ when the input almost matches. The browser cannot stop a running regular expression, so this page limits the input instead. Patterns are capped at 2,000 characters, text at 50,000, and the match list at 1,000. Patterns with nested quantifiers are flagged, and live matching pauses for them once the text is longer than 200 characters. Press Test to run such a pattern once, deliberately.

Pitfalls

Without g, only the first match is found, which is what exec and match do. With g on a regex object you reuse, lastIndex carries over between calls, so a second test() can return false for the same string.

. does not match a line break unless s is set. ^ and $ match at line breaks only with m. \w and \b are based on ASCII letters, digits and underscore even with u, so \w+ splits Grüße in two. (With u and i together, case folding also lets \w match the long s and the Kelvin sign.) Use \p{L} with the u flag for letters in any script.

Empty matches are shown as a thin marker. A pattern that can match the empty string, such as \d*, matches between every character; that is correct, not a bug of the tester.