Man I hate REGEX. Not for what it does, it’s a powerful weapon. It’s part sniper rifle, part bazooka and extremely useful in some situations. As powerful as it is though, it is a pain to write a good REGEX query; especially when you only do it occasionally. Thankfully, Bernard Peh and the gang over at WebProNews have released a primer for REGEX in PHP that makes it a little less painful to work with.

Appropriately titled Introduction To Regular Expressions In PHP, the article starts with a basic REGEX primer. It’s sparse on details but it discusses the different types of characters in a REGEX query. Properly formatted, this would be a great little cheat sheet to have handy.

Once you know the basics, the article dives into PHP’s implementation of PHP. It touches briefly on the fact that there are 2 implementation of REGEX -PCRE and POSIX-Extended – and how PHP implements them both. Then it dives into the heart of the subject and starts showing you code. (Yea sample code!) The samples, while a bit simple, are useful and do begin to show some of the power behind REGEX. Sadly, the article ends just as it is getting interesting. I would have liked to seen a few more paragraphs showing some more difficult queries. (Like how to pick apart the pieces of a URL, that one drove me crazy!)

That is not to say the article isn’t useful. It’s a great primer for anyone new to REGEX or just looking for a refresher course.

=C=