{"id":282,"date":"2009-08-13T10:48:17","date_gmt":"2009-08-13T10:48:17","guid":{"rendered":"http:\/\/kubasek.com\/blog\/pragmatic_craftsman\/?p=282"},"modified":"2009-08-13T10:48:17","modified_gmt":"2009-08-13T10:48:17","slug":"learning-regular-expressions","status":"publish","type":"post","link":"https:\/\/pragmaticcraftsman.kubasek.com\/?p=282","title":{"rendered":"Learning Regular Expressions"},"content":{"rendered":"<p>I have to admit, my regex skills are not that sharp. I read a <a href=\"http:\/\/pragmaticcraftsman.com\/2006\/07\/teach_yourself_regular_expressions_in_10_minutes.php\">book on Regular Expressions<\/a> before, but still, regex expressions just don&#8217;t stick in my mind. Too cryptic.<\/p>\n<p>Can you read the following?<\/p>\n<p><strong>\/^[a-z0-9_-]{3,16}$\/<\/strong><\/p>\n<p>The following explanation might help.<\/p>\n<p><strong>Description<\/strong>We begin by telling the parser to find the beginning of the string (^), followed by any lowercase letter (a-z), number (0-9), an underscore, or a hyphen. Next, {3,16} makes sure that are at least 3 of those characters, but no more than 16. Finally, we want the end of the string ($).<\/p>\n<p>String that matches: my-us3r_n4m3String that doesn&#8217;t match: wayt00_l0ngt0beausername (too long)<\/p>\n<p><strong>Clear<\/strong>, right? I love the description. It makes sense! This is an excerpt from an article <a href=\"http:\/\/net.tutsplus.com\/tutorials\/other\/8-regular-expressions-you-should-know\/\">8 Regular Expressions You Should Know<\/a>.<\/p>\n<p>This one is a bit more complicated.<\/p>\n<p><strong>\/^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$\/<\/strong><\/p>\n<p><strong>Description<\/strong>We begin by telling the parser to find the beginning of the string (^). Inside the first group, we match one or more lowercase letters, numbers, underscores, dots, or hyphens. I have escaped the dot because a non-escaped dot means any character. Directly after that, there must be an at sign. Next is the domain name which must be: one or more lowercase letters, numbers, underscores, dots, or hyphens. Then another (escaped) dot, with the extension being two to six letters or dots. I have 2 to 6 because of the country specific TLD&#8217;s (.ny.us or .co.uk). Finally, we want the end of the string ($).<\/p>\n<p>String that matches: john@doe.comString that doesn&#8217;t match: john@doe.something (TLD is too long)<\/p>\n<p><strong>Reference<\/strong><a href=\"http:\/\/net.tutsplus.com\/tutorials\/other\/8-regular-expressions-you-should-know\/\">8 Regular Expressions You Should Know<\/a>, nettuts (very good resource, btw)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have to admit, my regex skills are not that sharp. I read a book on Regular Expressions before, but still, regex expressions just don&#8217;t stick in my mind. Too cryptic. Can you read the following? \/^[a-z0-9_-]{3,16}$\/ The following explanation might help. DescriptionWe begin by telling the parser to find the beginning of the string [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-learning-thoughts"],"_links":{"self":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282"}],"version-history":[{"count":0,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions"}],"wp:attachment":[{"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pragmaticcraftsman.kubasek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}