Regular Expression Documentaion

Regular Expressions are super powerful, and are included in most programming languages.
Regardless of what programming language you use, regular expressions will make certain text processing tasks a breeze.
If you have ever looped through every character in a string of text searching for specific characters just stop and learn regular expressions.
You will be so glad you did.





Practice in your browser

You can practice writing javascript regular expressions in your browsers' javascript console (Ctrl+Shift+J) in Chrome.
Phone number example:
Navigate to: which is a list of US Senators.
Open your javascript console and type:

var regx1 = /((\d)?\(?\d{3}\)?[\s\-\.]\d{3}[\s\-\.]\d{4})/g;

Press enter and then type

document.documentElement.innerHTML =  document.documentElement.innerHTML.replace(regx1,"<h1>$1</h1>");

Press enter and all of the phone numbers will be wrapped in H1 tags.

Note: This could be accomplished much more easily in jQuery, however regular expressions are built in to practically every programming language and offer a lot of power for pattern matching and substitution.
This page for instance has the same class of contenttext for all of the table cell data. Even if the phone numbers had a separate class, we have no guarantee that there isn't other data in the cell. By using a regular expression we can match only the pattern we are interested in using very a very rigid expression.