{"id":456,"date":"2010-02-26T16:02:41","date_gmt":"2010-02-26T16:02:41","guid":{"rendered":"https:\/\/wade.one\/blog\/?p=456"},"modified":"2010-02-26T16:02:41","modified_gmt":"2010-02-26T16:02:41","slug":"regex-fu-phpuk2010","status":"publish","type":"post","link":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/","title":{"rendered":"Regex-fu #PHPUK2010"},"content":{"rendered":"<p>Good start: don&#8217;t use it unless you need to, there&#8217;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.<\/p>\n<p>Then the talk has become abstract, each point is prefixed with an odd statement such as &#8220;Only elephants remember everything&#8221; and &#8220;Not all matches are made in heaven&#8221; &#8211; people are getting it, but everything needs explaining before they get it!<\/p>\n<p>One very good point I have seen ignored many times is &#8220;try not to be greedy.&#8221; For example <strong>\/&lt;(.+)&gt;\/<\/strong> in the string &lt;a href=&#8221;&#8221;&gt;fdsfsd&lt;\/a&gt; will match the entire thing. To make it ungreedy, either use <strong>\/&lt;(.+?)&gt;\/<\/strong> or <strong>\/&lt;([^&gt;]+)<\/strong><strong>\/<\/strong> . Greedy matches can be 20+ times slower.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good start: don&#8217;t use it unless you need to, there&#8217;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. &#8230; <a href=\"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;Regex-fu #PHPUK2010&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[22],"class_list":["post-456","post","type-post","status-publish","format-standard","hentry","category-programming","tag-php-conference-2010"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Regex-fu #PHPUK2010 - wade.one<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Regex-fu #PHPUK2010 - wade.one\" \/>\n<meta property=\"og:description\" content=\"Good start: don&#8217;t use it unless you need to, there&#8217;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. ... Read More &quot;Regex-fu #PHPUK2010&quot; &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/\" \/>\n<meta property=\"og:site_name\" content=\"wade.one\" \/>\n<meta property=\"article:published_time\" content=\"2010-02-26T16:02:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1518\" \/>\n\t<meta property=\"og:image:height\" content=\"1506\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Wade\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:site\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wade\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/\"},\"author\":{\"name\":\"Wade\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/f9dedd948575256e77a44aa1417f63de\"},\"headline\":\"Regex-fu #PHPUK2010\",\"datePublished\":\"2010-02-26T16:02:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/\"},\"wordCount\":155,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"keywords\":[\"PHP Conference 2010\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/\",\"name\":\"Regex-fu #PHPUK2010 - wade.one\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\"},\"datePublished\":\"2010-02-26T16:02:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2010\\\/02\\\/26\\\/regex-fu-phpuk2010\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wade.one\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Regex-fu #PHPUK2010\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/\",\"name\":\"wade.one\",\"description\":\"wade womersley - york based software engineer\",\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wade.one\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\",\"name\":\"Wade Womersley\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"contentUrl\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"width\":202,\"height\":200,\"caption\":\"Wade Womersley\"},\"logo\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/f9dedd948575256e77a44aa1417f63de\",\"name\":\"Wade\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg\",\"caption\":\"Wade\"},\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/author\\\/wade\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Regex-fu #PHPUK2010 - wade.one","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/","og_locale":"en_GB","og_type":"article","og_title":"Regex-fu #PHPUK2010 - wade.one","og_description":"Good start: don&#8217;t use it unless you need to, there&#8217;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. ... Read More \"Regex-fu #PHPUK2010\" &raquo;","og_url":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/","og_site_name":"wade.one","article_published_time":"2010-02-26T16:02:41+00:00","og_image":[{"width":1518,"height":1506,"url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png","type":"image\/png"}],"author":"Wade","twitter_card":"summary_large_image","twitter_creator":"@wadewomersley","twitter_site":"@wadewomersley","twitter_misc":{"Written by":"Wade","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/#article","isPartOf":{"@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/"},"author":{"name":"Wade","@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/f9dedd948575256e77a44aa1417f63de"},"headline":"Regex-fu #PHPUK2010","datePublished":"2010-02-26T16:02:41+00:00","mainEntityOfPage":{"@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/"},"wordCount":155,"commentCount":0,"publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"keywords":["PHP Conference 2010"],"articleSection":["Programming"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/","url":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/","name":"Regex-fu #PHPUK2010 - wade.one","isPartOf":{"@id":"https:\/\/wade.one\/blog\/#website"},"datePublished":"2010-02-26T16:02:41+00:00","breadcrumb":{"@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wade.one\/blog\/2010\/02\/26\/regex-fu-phpuk2010\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wade.one\/blog\/"},{"@type":"ListItem","position":2,"name":"Regex-fu #PHPUK2010"}]},{"@type":"WebSite","@id":"https:\/\/wade.one\/blog\/#website","url":"https:\/\/wade.one\/blog\/","name":"wade.one","description":"wade womersley - york based software engineer","publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wade.one\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3","name":"Wade Womersley","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","contentUrl":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","width":202,"height":200,"caption":"Wade Womersley"},"logo":{"@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png"}},{"@type":"Person","@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/f9dedd948575256e77a44aa1417f63de","name":"Wade","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/94100ef7361b8aaac136b852c8df93bdd10942165a122d5c56e4466cc403e5d9?s=96&d=retro&r=pg","caption":"Wade"},"url":"https:\/\/wade.one\/blog\/author\/wade\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":573,"url":"https:\/\/wade.one\/blog\/2012\/02\/05\/regular-expression-regex-for-date-part-extractionarray-split\/","url_meta":{"origin":456,"position":0},"title":"Regular Expression (Regex) For Date part extraction\/array split","author":"Wade","date":"February 5, 2012","format":false,"excerpt":"Needed to use this recently to create a specificity parameter for an API at work, it gives you a key\/value array from an ISO date string regardless of what is actually set in the string (e.g. if you give 2011-06-07 04 you'll get an array back as array('year'=>2011, 'month' =>\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":938,"url":"https:\/\/wade.one\/blog\/2015\/07\/06\/cloudant-ibm-query-indexing-arrays-directly-using-erlang\/","url_meta":{"origin":456,"position":1},"title":"Cloudant (IBM) Query &#8211; Indexing arrays directly using Erlang","author":"Wade","date":"July 6, 2015","format":false,"excerpt":"Really short post this one on indexing using Cloudant Query\u00a0to index arrays in your document, e.g. documents that have a field like this: { \"ids\": [ \"alpha\", \"bravo\", \"charlie\" ] } I was reading the documentation and just could not get it to index these items using anything but the\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/wade.one\/blog\/wp-content\/uploads\/2015\/07\/SmJYeZ0r_400x400.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1172,"url":"https:\/\/wade.one\/blog\/2026\/04\/05\/what-makes-an-api-feel-nice-to-work-with\/","url_meta":{"origin":456,"position":2},"title":"What Makes an API Feel Nice to Work With","author":"Wade","date":"April 5, 2026","format":false,"excerpt":"A good API is not just functional. It is predictable, consistent, and easy to use without a lot of guesswork.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":437,"url":"https:\/\/wade.one\/blog\/2010\/01\/31\/mysql-and-binary16-the-reasonsbenefitsdrawbacks-mysql\/","url_meta":{"origin":456,"position":3},"title":"MySQL and Binary(16) &#8211; The Reasons\/Benefits\/Drawbacks (#mysql)","author":"Wade","date":"January 31, 2010","format":false,"excerpt":"I recently posted an article about using BINARY(16) for storing MD5's as unique identifiers instead of simple integer ID's (usually auto increment); in that article I touched on one of the benefits, reducing JOIN's, but there are other reasons for doing it too, so I thought I'd post an article\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":629,"url":"https:\/\/wade.one\/blog\/2012\/10\/15\/using-amazon-ec2-with-c-net\/","url_meta":{"origin":456,"position":4},"title":"Using Amazon EC2 with C# .net","author":"Wade","date":"October 15, 2012","format":false,"excerpt":"Amazon's EC2 platform has a very in-depth console which allows you to do a lot, but what if you want to automate some of the processes or handling servers? I've been working with EC2 a lot recently and automating server starting\/stopping based on parameters of the system we use here\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":431,"url":"https:\/\/wade.one\/blog\/2010\/01\/29\/mysql-binary16-and-scalability\/","url_meta":{"origin":456,"position":5},"title":"MySQL &#8211; Binary(16) and scalability","author":"Wade","date":"January 29, 2010","format":false,"excerpt":"Over the past few months at work, we've seen our database grown from silly big to really silly big, it's still a way to go to get to the size of the big boys such as Facebook etc. but it's still a database stored in MySQL that most day-to-day PHP\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":0,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"wp:attachment":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}