{"id":20335,"date":"2017-03-05T18:04:01","date_gmt":"2017-03-05T18:04:01","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=20335"},"modified":"2017-03-05T18:04:01","modified_gmt":"2017-03-05T18:04:01","slug":"perl-regular-expressions-yesterdays-code-explained","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-regular-expressions-yesterdays-code-explained\/","title":{"rendered":"Perl:  regular expressions:  yesterday&#8217;s code explained"},"content":{"rendered":"<h1>The tutor tells the workings of yesterday&#8217;s pattern matching example.<\/h1>\n<p>In <a href=\"?p=20314\">yesterday&#8217;s post<\/a> I mention that the regular expression<\/p>\n<p style=\"font-family:monospace;color:#995599\">if ($input=~\/item1[^0-9]*[0-9]*.?[0-9]{0,2}\/i)<\/p>\n<p>can find the pattern <em>item1&#8230;.$#####.##<\/em> in a longer string.  Here are some explanatory points:<\/p>\n<ul>\n<li>=~ is the pattern find operator, which finds the pattern defined on the right in the string on the left.<\/li>\n<li>Between \/ \/ is the pattern to be matched.<\/li>\n<li>item1, between \/ \/, means the literal string item1.<\/li>\n<li>[^0-9]* means <em>not<\/em> numbers, while the asterisk means 0 or more.<\/li>\n<li>[0-9]* means numbers only, 0 or more of them.<\/li>\n<li>.? means possibly a single decimal point, but maybe none.<\/li>\n<li>[0-9]{0,2} means numbers, 0 to 2 of them.<\/li>\n<li>The i after the closing slash means case insensitivity:  item1 or Item1 will be found.<\/li>\n<li>The match, if found, is put in the variable $&#038;, which can afterwards be printed or fetched as desired.<\/li>\n<\/ul>\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.tutorialspoint.com\/perl\/perl_regular_expression.htm\">www.tutorialspoint.com<\/a><\/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 tells the workings of yesterday&#8217;s pattern matching example. In yesterday&#8217;s post I mention that the regular expression if ($input=~\/item1[^0-9]*[0-9]*.?[0-9]{0,2}\/i) can find the pattern item1&#8230;.$#####.## in a longer string. Here are some explanatory points: =~ is the pattern find &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-regular-expressions-yesterdays-code-explained\/\"> <span class=\"screen-reader-text\">Perl:  regular expressions:  yesterday&#8217;s code explained<\/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,104,710,2160],"class_list":["post-20335","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-pattern-matching","tag-perl","tag-regex","tag-regular-expression"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/20335","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=20335"}],"version-history":[{"count":19,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/20335\/revisions"}],"predecessor-version":[{"id":20354,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/20335\/revisions\/20354"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=20335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=20335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=20335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}