Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2010
  • February
  • 26
  • Regex-fu #PHPUK2010

Regex-fu #PHPUK2010

Posted on February 26, 2010 By Wade No Comments on Regex-fu #PHPUK2010
Programming

Good start: don’t use it unless you need to, there’s plenty of alternatives, e.g. DOMXML, str_replace, etc. Also PHP5+ has lots of filters for email validation and URL validation etc, function calls you can make rather than complex regular expressions. Regular expressions can slow down quickly due to back tracking, pattern complexity and long strings.

Then the talk has become abstract, each point is prefixed with an odd statement such as “Only elephants remember everything” and “Not all matches are made in heaven” – people are getting it, but everything needs explaining before they get it!

One very good point I have seen ignored many times is “try not to be greedy.” For example /<(.+)>/ in the string <a href=””>fdsfsd</a> will match the entire thing. To make it ungreedy, either use /<(.+?)>/ or /<([^>]+)/ . Greedy matches can be 20+ times slower.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: PHP Conference 2010

Post navigation

❮ Previous Post: #PHPUK2010 Part 2 (MySQL stuff)
Next Post: Large Hardon Collider breaks energy record ❯

You may also like

PHP
PHP 8.5.4 Released: Upgrade if You’re on 8.5
March 25, 2026
Programming
I Trust Boring Infrastructure More Than Clever Infrastructure
April 4, 2026
Programming
The Hardest Part of Serverless Is Not the Code
April 12, 2026
Programming
The Best Engineering Decisions Usually Remove Work
April 11, 2026

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown