Regular expression tester

This online calculator allows user to experiment with regular expressions.

This page exists due to the efforts of the following people:



Created: 2011-08-04 21:40:17, Last updated: 2021-02-24 07:10:08
Creative Commons Attribution/Share-Alike License 3.0 (Unported)

This content is licensed under Creative Commons Attribution/Share-Alike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work Also, please do not modify any references to the original work (if any) contained in this content.

I was not too fond of regular expressions, considering them as a strange and mysterious beast. But lately, I've been forced to use all their powers, so I get used to them.

From my experience, if you want to understand regular expressions, you have to find a good description, which I have found in O'Reilly's book "C# 3.0" by Joseph and Ben Albahari. An excellent chapter about regular expressions.

Regular expressions are cool stuff, and all programming languages have implementations of them, and Javascript, which is used to write calculators for this site.

Javascript has a RegExp object, which does the magic.

First, it has method test(string) - which returns true if it finds regular expression in the source text (matched) or false otherwise.

Second, it has method exec(string) - which extracts everything that is matched. It returns an array of results.

Third, and most importantly, we can use RegExp to replace the string by calling source_string.replace(regex, replace_string).

Below is the calculator which allows you to play with regular expressions. You should enter source text, regular expression, modifiers (used in replacement), and replacement expression. After that, you will get calls to test, exec, and replace upon source text.

By default, it extracts all digits which look like phone numbers and formats them.

PLANETCALC, Regular expressions sandbox

Regular expressions sandbox

Result of "test" method
Result of "exec" method
Result of "replace" method

URL copied to clipboard
PLANETCALC, Regular expression tester