{"id":17,"date":"2011-09-05T22:49:39","date_gmt":"2011-09-06T06:49:39","guid":{"rendered":"https:\/\/dotcomdotat.com\/blog\/?p=17"},"modified":"2011-09-05T22:49:39","modified_gmt":"2011-09-06T06:49:39","slug":"the-old-adage-on-regular-expressions","status":"publish","type":"post","link":"https:\/\/dotcomdotat.com\/blog\/2011\/09\/the-old-adage-on-regular-expressions\/","title":{"rendered":"The old adage on regular expressions"},"content":{"rendered":"<p>A co-worker is fond of saying, &#8220;You have a problem so you solve it with a regular expression. Now you have two problems.&#8221;<\/p>\n<p>Regular expressions are powerful tools but they can easily cause unforeseen complications. The script I&#8217;ve been trying to improve contains a section for stripping HTML. It uses <a title=\"HTML::Strip\" href=\"http:\/\/search.cpan.org\/~kilinrax\/HTML-Strip-1.06\/Strip.pm\">HTML::Strip<\/a> to do this but does a lot of pre- and post-processing with a series of regular expressions. If the script was run with the stripping feature enabled an extra 21 minutes to the running time. You can imagine how quickly that adds up.<\/p>\n<p>Looking at the regexes I was able to easily tweak them a bunch of them. Some I was able to combine through the use of classes, some I removed unnecessary groupings. At the end I&#8217;d reduced the processing time by about 8 1\/2 minutes. I&#8217;m not completely celebrating yet as I&#8217;m still working on verifying the new data, but currently all the expected IDs are in place and things look good.<\/p>\n<p>13 minutes is still a lengthy processing time, but it&#8217;s a big improvement and I think I may still be able to whittle it down. While I spotted numerous issues with the old regexes, I did actually learn a couple things while doing this. Regular Expressions are far more complex than they seem at first and it&#8217;s very worthwhile to familiarize yourself with how they work. The <a title=\"Perl Regular Expressions\" href=\"http:\/\/perldoc.perl.org\/perlre.html\">perlre<\/a> section at <a title=\"Perl Programming Documentation \" href=\"http:\/\/perldoc.perl.org\">perldoc.perl.org<\/a> is a wonderful resource but before trying to absorbing it all I&#8217;d look for a primer. <a title=\"RObert's Perl Tutorial\" href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl Tutorial<\/a> has an excellent section on regular expressions. For a more pointed document, Steve Litt&#8217;s <a title=\"Steve Litt's Perls of Wisdom: Perl Regular Expressions\" href=\"http:\/\/www.troubleshooters.com\/codecorn\/littperl\/perlreg.htm\">Perl Regular Expressions<\/a> is the top Google result and looks quite good.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A co-worker is fond of saying, &#8220;You have a problem so you solve it with a regular expression. Now you have two problems.&#8221; Regular expressions are powerful tools but they can easily cause unforeseen complications. The script I&#8217;ve been trying to improve contains a section for stripping HTML. It uses HTML::Strip to do this but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,3],"tags":[11],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-legacy-issues","category-perl","tag-regex"],"_links":{"self":[{"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":1,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":18,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions\/18"}],"wp:attachment":[{"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dotcomdotat.com\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}