This post originated from an RSS feed registered with Web Buzz
by Douglas Clifton.
Original Post: PHP Regular Expression Clinic
Feed Title: blogZero
Feed URL: http://loadaveragezero.com/app/s9y/index.php?/feeds/index.rss1
Feed Description: Web Development News, Culture and Opinion
The loadaverageZeroApachelog files are full of instances of people searching for regular expression tutorials. Probably because I list several good ones, and the search engines oblige me by indexing them.
Somehow, I missed Andrei Zmievski's PHP Regular Expression Clinic. And it's easily the best of the lot. If you're not familiar with Andrei's work, he's been the principal PHP developer since 1999, works as a member of the Core Software Infrastructure team at Yahoo!, is the author of the PHP Developer's Cookbook, the PHP-GTK GUI Toolkit extension, and is co-author of the Smarty templating engine.
He also happens to be the guy who wrote the PCRE PHP extension. That's quite a resume. Now don't assume he wrote the PCRE library itself, that distinction belongs to Philip Hazel. And PHP is by no means the only software that uses the PCRE library, you can find it as part of Apache, Python, and many other interesting open-source projects. And we can't forget about Perl itself, although it obviously doesn't need a compatibility library.
Some advice for Web developers: regular expressions are powerful, but they come at a price. I have seen countless examples of code that could easily have been implemented using standard string search and comparison functions. Use regular expressions only when you need to, and when you do, use the preg family of functions because they are faster, and more powerful. In my opinion, the extended regex (ereg) functions should be removed from the PHP core. If people really want to use them, they can compile them in or access them as a runtime extension.