Home | Programming Resources |     Share This Page
Regular Expression Laboratory
A JavaScript-based regular expression testing area

— Copyright 2013, P. Lutus Message Page

Introduction
Regular expressions are becoming the method of choice for a wide variety of text processing tasks. They are powerful, subtle, some may argue too cryptic, but once mastered they greatly simplify text processing.

This page allows you to create and test regular expressions quickly and interactively. It can be thought of as a "regular expression calculator", a handy way to find out whether a particular expression will produce the results you expect.

In the first phase, the user pastes the desired sample text into the source window (or uses the default text), then enters a search expression and presses the "Enter" key or clicks the "Search" button. The results window will display any matching areas of the sample text highlighted like this. This feature allows the user to tune the search expression interactively — and quickly.

In the second phase, the user enters a replacement expression and presses the "Enter" key or clicks the "Replace" button. The results window will show the replacements.

JavaScript regular expressions (as used in this page) follow the Java/Perl convention that capture references in the replacement field are identified as "$1","$2" ... etc.. But confusingly, for backreferences in the search field, use "\1","\2" ... etc..

An example of the use of backreferences in the search field would be:

(\w)\1
This example would find paired letters.

Below is a list of online references for those who need to learn regular expressions. Most of these sources assume a language environment like Perl, but the information is sufficiently relevant to be useful. While reading these tutorials, remember that, although search expressions are very often shown as /expression/, in this program the expression without the /delimiters/ is all that is used. Here is the list:

There are also many excellent printed books on the topic of regular expressions. One example I recommend is "Mastering Regular Expressions" by Jeffrey E. F. Freidl (published by O'Reilly & Associates, Inc.).

Source Window
This window contains the source text, the text you want to experiment on. Just paste any desired text into this box, or use the default sample.

Regular Expression
This is the area where you enter a regular expression for testing.

Search: Replace:
Case Multiline Global "." = all Result summary panel
Results Window
This window contains the result of searches and replacements.

 

Home | Programming Resources |     Share This Page