|
I
came across an article on Advanced Regular Expressions by
George Schlossnagle in an April 2004 edition of PHP Architecht
this morning. It has been hiding in a drawer for a year. The
article is outstanding, and 2 of the features I could most
use in everyday life are Pattern Naming and Commenting your
regex. I'm assuming you already have a good understanding
of how preg_match works.
I
know alot of the time I'll come across a regex that looks
like:
^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?$
This
is a mild example but honestly that will take you a nice chunk
of time to decode into what it is actually looking for. Then
you have to watch the parenthesis to figure out what array
index each variable you need is going to be in.
What
this tutorial will cover:
1.
How to create a simple RegEx match
2.
How to add pattern names to your regular expressions
3.
How to add comments to your regular expressions
PART
1 EASY REGEX
Lets
take the string below and use it in all the examples through
the tutorial. This will make it easier to get the hang of
everything.
|