Skip to content

Test regex

Write a regular expression and a text to try it on. The engine is the browser’s own, the same one behind any JavaScript code: if that is where you will use it, what you see here is what you will get.

Your text stays on your device: nothing is uploaded

0 characters

Active flags: g. Change them under “Advanced options”.

Advanced options

Result

Paste something on the left: the result appears as you type.

How it works

The engine is the browser’s own, the same one behind any JavaScript: what works here works in your code, if your code is JavaScript. For every match you see the position, the line and the captured groups, named ones included. Some expressions take an enormous time on badly built input — “(a+)+b” against a row of “a” never finishes — and here the search stops after one second and tells you so, instead of freezing the page. Safari gives up on its own even sooner, without saying so: there you see “No matches” even when there was one. If such an expression finds nothing in Safari, try it in another browser. If it happens to you, it would happen to your program too: it is the sign of an expression to rewrite.

Frequently asked questions

Do I type the slashes /…/ and the flags?
No: type just the expression and switch the flags on with the toggles under “Advanced options”. If you type “/\d+/g”, the slashes and the g are searched for as text. Backslashes are written once, as between slashes in code; inside a quoted string in your code, such as “new RegExp("\\d+")”, they have to be doubled.
Will a pattern written for Python, PHP or Java work the same?
The basics will, but the flavour is JavaScript’s. Named groups are written “(?<name>…)”, not “(?P<name>…)” as in Python; possessive quantifiers like “a++” and atomic groups “(?>…)” do not exist; and “\A” and “\Z” are not anchors: use “^” and “$” without the m flag.
Why does it say the expression is taking too long?
Because on that text the engine worked for more than a second without reaching an answer, and the search was stopped. The typical case is nested repetition, such as “(a+)+” or “(\w*)*”: when the text almost matches, the engine tries every way of splitting the characters between the two repetitions, and the number of ways doubles with each character. Rewrite the expression without repeating a repetition, for example “a+” instead of “(a+)+”. A program using it on such a text would freeze in the same way. In Safari this warning does not appear: the browser stops the search itself and answers “No matches”, even if there was one.
When do I need Unicode mode (u)?
When you use classes like “\p{L}”, which matches any letter, accented ones included, or when you want the dot to treat an emoji as a single character. It is also stricter: needless escapes, such as “\-” outside square brackets, become errors instead of passing silently.
Can I test a replacement too?
No, this page only searches. But the groups listed under each match are exactly what a replacement would insert: group 1 is “$1”, a named group is “$<name>”. If a group “did not participate”, nothing would be inserted in its place.

What you paste is never uploaded. Anywhere.

The text you type stays in your browser’s memory: no request goes out while you type. You can paste something confidential.

  • Processed locallyEverything happens on this page.
  • Nothing to upload, nothing to wait forNothing to upload, no waiting.
  • Nothing to deleteWe keep nothing: nothing reaches us.
YOUR DEVICEyour fileprocessingthe resultservernever gets here

Other tools in this category