{"id":13182,"date":"2015-11-23T00:33:51","date_gmt":"2015-11-23T00:33:51","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=13182"},"modified":"2015-11-23T00:33:51","modified_gmt":"2015-11-23T00:33:51","slug":"perl-regular-expression-explanation","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-regular-expression-explanation\/","title":{"rendered":"Perl:  regular expression explanation"},"content":{"rendered":"<h1>The tutor follows up on his post about the variable password checker.<\/h1>\n<p>In my <a href=\"?p=13150\">Nov 18<\/a> post I show a short script that checks a three-digit entry for a match with the pattern <span style=\"font-family:monospace\">m[any character]m<\/span>.  The entry <span style=\"font-family:monospace\">m4m<\/span> is a match, for example.  However, <span style=\"font-family:monospace\">m4mi<\/span> is not a match (too long).  Neither is <span style=\"font-family:monospace\">tom<\/span>; it doesn&#8217;t follow <span style=\"font-family:monospace\">m[character]m<\/span>.<\/p>\n<p>The code that can distinguish the pattern<\/p>\n<p><span style=\"font-family:monospace\">m[any character]m<\/span><\/p>\n<p>is<\/p>\n<p><span style=\"font-family:monospace;color:brown\">if ($word=~\/^n.n$\/){<br \/>\nprint &#8220;correct&#8221;;<br \/>\n}<br \/>\n<\/span><\/p>\n<p>The <span style=\"font-family:monospace\">=~<\/span> means &#8220;contains match&#8221;.  The period in the middle means &#8220;any single character&#8221;. The <span style=\"font-family:monospace\">^<\/span> means the match must occur at the beginning of <span style=\"font-family:monospace\">$word<\/span>, while the <span style=\"font-family:monospace\">$<\/span> means it must occur at the end.  Therefore, the string can only be three characters long.<\/p>\n<p>HTH:)<\/p>\n<p>Source:<\/p>\n<p>McGrath, Mike.  <u>Perl in easy steps<\/u>.  Southam:  Computer Step, 2004.<\/p>\n<p><a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl tutorial<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor follows up on his post about the variable password checker. In my Nov 18 post I show a short script that checks a three-digit entry for a match with the pattern m[any character]m. The entry m4m is a &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-regular-expression-explanation\/\"> <span class=\"screen-reader-text\">Perl:  regular expression explanation<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[1201,173,709],"class_list":["post-13182","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-pattern-matching","tag-perl-programming","tag-regular-expressions"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/13182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=13182"}],"version-history":[{"count":14,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/13182\/revisions"}],"predecessor-version":[{"id":13196,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/13182\/revisions\/13196"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=13182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=13182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=13182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}