{"id":3366,"date":"2011-12-29T07:00:31","date_gmt":"2011-12-29T13:00:31","guid":{"rendered":"http:\/\/humairahmed.com\/blog\/?p=3366"},"modified":"2012-01-04T23:13:04","modified_gmt":"2012-01-05T05:13:04","slug":"perl-using-pattern-sequence-memory-with-regular-expressions","status":"publish","type":"post","link":"https:\/\/humairahmed.com\/blog\/?p=3366","title":{"rendered":"Perl &#8211; Using Pattern-sequence Memory with Regular Expressions"},"content":{"rendered":"<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=Perl+-+Using+Pattern-sequence+Memory+with+Regular+Expressions\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/humairahmed.com\/blog\/?p=3366\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><\/div><p>Pattern-sequence memory is very useful when you want to match the same character in several places but don&#8217;t care which character you match as long as all occurrences are the same character. For example, the below code matches the date format &#8220;dd-mm-yy&#8221; where the dashes can be any two of the same non-word characters (in regex notation the range would be [^_0-9a-zA-Z]). Pattern sequences are stored in memory from left to right, so &#8220;\\1&#8221; would represent the first match. <!--more--> <div id=\"attachment_3367\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_code.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3367\" src=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_code.png\" alt=\"Using pattern-sequence memory with regular expressions\" title=\"Using pattern-sequence memory with regular expressions\" width=\"550\" height=\"251\" class=\"size-full wp-image-3367\" srcset=\"https:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_code.png 550w, https:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_code-300x136.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-3367\" class=\"wp-caption-text\">Using pattern-sequence memory with regular expressions<\/p><\/div><\/p>\n<p>The input file is called &#8220;dates.txt&#8221; and contains the below data. The Perl script should only print out the three lines of text in the file that meet the regular expression criteria: &#8220;12-29-11&#8221;, &#8220;12.29.11&#8221;, and &#8220;12 29 11&#8221;. <\/p>\n<p><strong>&#8220;dates.txt&#8221; file input and Perl script output<\/strong><div id=\"attachment_3369\" style=\"width: 100px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_file.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3369\" src=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_file.png\" alt=\"&quot;dates.txt&quot; input file\" title=\"&quot;dates.txt&quot; input file\" width=\"90\" height=\"109\" class=\"size-full wp-image-3369\" \/><\/a><p id=\"caption-attachment-3369\" class=\"wp-caption-text\">&quot;dates.txt&quot; input file<\/p><\/div><\/p>\n<p><div id=\"attachment_3373\" style=\"width: 82px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_out.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3373\" src=\"http:\/\/humairahmed.com\/blog\/wp-content\/uploads\/2011\/12\/perl_pattern_seq_out.png\" alt=\"Perl script - pattern-sequence memory code output\" title=\"Perl script - pattern-sequence memory code output\" width=\"72\" height=\"56\" class=\"size-full wp-image-3373\" \/><\/a><p id=\"caption-attachment-3373\" class=\"wp-caption-text\">Perl script - pattern-sequence memory code output<\/p><\/div><br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pattern-sequence memory is very useful when you want to match the same character in several places but don&#8217;t care which character you match as long as all occurrences are the same character. For example, the below code matches the date &hellip; <a href=\"https:\/\/humairahmed.com\/blog\/?p=3366\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[382,5,3],"tags":[927,926,925,930,386,574,560,573,928,929],"class_list":["post-3366","post","type-post","status-publish","format-standard","hentry","category-perl","category-programming","category-technology","tag-pattern-memory","tag-pattern-sequence","tag-pattern-sequence-memory","tag-pattern-sequence-memory-with-regular-expressions","tag-perl-2","tag-perl-regular-expressions","tag-regex","tag-regular-expressions","tag-sequence-memory","tag-using-pattern-sequence-memory-with-regular-expressions"],"_links":{"self":[{"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3366"}],"version-history":[{"count":35,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3366\/revisions"}],"predecessor-version":[{"id":3459,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3366\/revisions\/3459"}],"wp:attachment":[{"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/humairahmed.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}