{"id":20314,"date":"2017-03-04T19:40:02","date_gmt":"2017-03-04T19:40:02","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=20314"},"modified":"2017-03-04T19:44:45","modified_gmt":"2017-03-04T19:44:45","slug":"perl-using-regex-aka-regular-expression-pattern-matching-to-find-an-item-and-its-price-in-a-string","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-using-regex-aka-regular-expression-pattern-matching-to-find-an-item-and-its-price-in-a-string\/","title":{"rendered":"Perl:  using regex (aka regular expression, pattern matching) to find an item and its price in a string"},"content":{"rendered":"<h1>The tutor demonstrates a Perl regular expression that finds an item name and its price in a string.<\/h1>\n<p>Suppose you believe that the price of item1 is given in a string, but aren&#8217;t sure how exactly it&#8217;s said.  It could, for instance, say<\/p>\n<p style=\"font-family:serif;font-size:110%\">Item1:  $56.77<\/p>\n<p>or <\/p>\n<p style=\"font-family:serif;font-size:110%\">He likes the price of item1 not above $101.21, but understands it may go up soon&#8230;.<\/p>\n<p>A search for the portion of the string containing <i>item1&#8230;$####.##<\/i> can be executed as follows:<\/p>\n<p style=\"color:#772277;font-family:monospace;font-size:120%\">\n#!\/usr\/bin\/perl<br \/>\nprint &#8220;Enter the string, please.&#8221;;<br \/>\n$input=&#60;STDIN&#62;;<br \/>\nif($input=~\/item1[^0-9]*[0-9]*.?[0-9]{0,2}\/i){<br \/>\nprint &#8220;$&#038;\\n&#8221;;<br \/>\n}<br \/>\nelse{<br \/>\nprint &#8220;Sorry:  no match.\\n&#8221;;<br \/>\n}\n<\/p>\n<p>I&#8217;ll be explaining the workings of this code next post:)<\/p>\n<p>Source:<\/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>McGrath, Mike.  <u>Perl in easy steps<\/u>.  Southam:  Computer Step, 2004.<\/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 demonstrates a Perl regular expression that finds an item name and its price in a string. Suppose you believe that the price of item1 is given in a string, but aren&#8217;t sure how exactly it&#8217;s said. It could, &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-using-regex-aka-regular-expression-pattern-matching-to-find-an-item-and-its-price-in-a-string\/\"> <span class=\"screen-reader-text\">Perl:  using regex (aka regular expression, pattern matching) to find an item and its price in a string<\/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-20314","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\/20314","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=20314"}],"version-history":[{"count":20,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/20314\/revisions"}],"predecessor-version":[{"id":20334,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/20314\/revisions\/20334"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=20314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=20314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=20314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}