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 le
tters.
Below is a list of online references for those who need to learn regular expressions. While reading these tutorials, remember that, although search expressions are very often shown as /expression/, in this program an expression without the /delimiters/ is the correct syntax. 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.).