Regular Expressions
Fun with Regular Expressions
What are regular expressions?  Regular expressions are a widely accepted way of finding locating patterns contained within text.  Almost every programming language out there supports them in one form or another.  I'm not sure why they ended up under PHP.  Probably because I was using them in a PHP project at the time I created this page.

The power of regular expressions is unbelievable.  Anyone who works with text in some form or another can benefit greatly from learning to use regular expressions.  Below are some of examples of using regular expressions.

One of the most common uses of regular expressions is to do text pattern matching
Find all HTML span tags and their attributes:
Another common use of regular expressions is to replace text with other text.
In this example, we switch Test_1 and Test_2 in the text
Test_1 - Test_2
:1,$s/\(Test_1\).*\(Test_2\)/\2 - \1
The previous example made use of regular expressions recording functionality.  Everything between \( \) gets recorded for later use in the regular expression by using \1 where 1 is the occurence of the recording.

Remeber in regular expressions if you want to match reserved reserved regular expression like ? ^ characters you must enclose them in [ ].