{"id":194,"date":"2014-07-23T00:45:27","date_gmt":"2014-07-23T00:45:27","guid":{"rendered":"http:\/\/www.minotaurdesign.com\/blog\/?p=194"},"modified":"2014-07-23T00:46:25","modified_gmt":"2014-07-23T00:46:25","slug":"notes-codestock-2014%e2%80%b2s-regular-expressions-presentation","status":"publish","type":"post","link":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/","title":{"rendered":"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation"},"content":{"rendered":"<p>Brian Friesen&#8217;s talk on Regular Expressions was probably my favorite of the conference.  You gotta admire a guy who builds a regular expression engine to properly demo and train folks up on the &#8216;devil&#8217;s language&#8217; (as I and others I&#8217;ve known have called it)&#8230;  Folks that hate regex and those that live and breathe the stuff all got something from the session.  Good stuff.<\/p>\n<h3>Regular Expressions &#8211; now you have two problems<\/h3>\n<p>Brian Friesen<br \/>\n<a href=\"https:\/\/twitter.com\/@brianfriesen\" target=\"_blank\">@brianfriesen<\/a><\/p>\n<p>Works at Quicken Loans (side note, I used QL last year &#8211; hands down the best UX I&#8217;ve ever seen in a mortgage product\/service)<\/p>\n<p><a href=\"github.com\/QuickenLoans\/RegExpose\" target=\"_blank\">github.com\/QuickenLoans\/RegExpose<\/a><\/p>\n<p><a href=\"http:\/\/Regexper.com\" target=\"_blank\">Regexper.com<\/a><\/p>\n<p><a href=\"http:\/\/Regular-expressions.info\" target=\"_blank\">Regular-expressions.info<\/a><\/p>\n<p><strong>The Bible:<\/strong><br \/>\n<em>Mastering Regular Expressions<\/em> by Jeffery Friedl<br \/>\n&#8211; can read the first 2\/5 of the book and you have enough<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p><strong>1. RegEx are hierarchical<\/strong><\/p>\n<p>Root node = the whole expression<\/p>\n<p>ABC would tree out like this:<\/p>\n<p>ABC &#8211; root<br \/>\nA &#8211; character literal<br \/>\nB &#8211; character literal<br \/>\nC &#8211; character literal<\/p>\n<p><strong>2. RegEx do their thing sequentially<\/strong><\/p>\n<p>A RegEx will match if each of its child nodes matches in sequence<br \/>\nAfter a match, the RegEx engine will continue trying to find further matches until it has covered the entire string.<\/p>\n<p><strong>RegEx are by default case-sensitive<\/strong><\/p>\n<p><strong>Character classes are surrounded by square brackets<\/strong><br \/>\n&#8211; for a range, use a dash.<br \/>\n&#8211; if you need a dash in the match, put it at the beginning of your set within square brackets<br \/>\n&#8211; you can also include specific characters or numbers to match against<br \/>\n&#8211; can include a-z and A-Z, or you can pass an additional param to ignore case<br \/>\n&#8211; a negated character class = add a &#8220;^&#8221; carat character before a match. ie [^a-f0-9] would ignore a-f<\/p>\n<p><strong>Shorthand matches<\/strong><br \/>\n&#8211; \\d is the same as [0-9]<br \/>\n&#8211; \\D is the same as [^0-9]<br \/>\n&#8211; \\s matches whitespace chars<br \/>\n&#8211; \\w is the same as any word character, meaning [A-Za-z0-9_]<br \/>\n&#8211; . matches any character, depending on options (ie except for new line character)<\/p>\n<p><strong>Alternation<\/strong><br \/>\n(it&#8217;s a pipe dream)<\/p>\n<p>| character means &#8220;or&#8221;<br \/>\n&#8211; linos|tigers|bears &#8216;lions&#8217; would match, but regExp doesn&#8217;t know if its the BEST match, so it saves state (a breadcrumb) and moves to check the other choices.<br \/>\n&#8211; if a match hits on the last option in a set of choices, no state will be saved, no breadcrumbs etc.<\/p>\n<p><strong>Quantifiers (quantifiers are always AFTER)<\/strong><br \/>\n(Because sometimes, quantity trumps quality)<\/p>\n<p><strong>Greedy Quantifiers<\/strong> (greedy means quantifier always wants more, ie. will keep going)<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n&#8211; ? = optional<br \/>\n&#8211; * = will match zero, will match many<br \/>\n&#8211; PO*P would match &#8220;PP&#8221; as well as &#8220;POOP&#8221;<br \/>\n&#8211; + = must match at least once to succeed<br \/>\n&#8211; NO+! would match &#8220;NO!&#8221; as well as &#8220;NOOOOOOOOOOO!&#8221;<br \/>\n&#8211; {} = match a specific number of things<br \/>\n&#8211; \\d{3} = this means match exactly 3 digits<br \/>\n&#8211; \\d{3,15} = this means match at least 3, but up to 15<br \/>\n&#8211; \\d{3,} = this means match at least 3 with no high end limit<\/p>\n<p>Ultimate lazy quantifier: .*<\/p>\n<p>Causion against using &#8220;*.&#8221; &#8211; can lead to a match failing since the greedy &#8216;any character as many as possible&#8217; matching could lead to skipping more specific matches after the *.<\/p>\n<p><strong>Lazy Quantifiers <\/strong>&#8211; will only match as much as is needed, without going overboard<br \/>\nOnce a match is made it will pass control to the next match paramater until it&#8217;s needed again&#8230;<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n.*? = Lazy<br \/>\n{3,5}? = also Lazy (in this case, once 3 digits were matched, the next node in regexp would be matched)<\/p>\n<p>&#8211; ab.*?cd would match &#8220;abc12345cd&#8221; with the lazy quantifier returning to the &#8216;c&#8217; character repeatedly before going back to the next number character<\/p>\n<p><strong>More alternation<\/strong><br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n(?:white|dog|brick) house<br \/>\n&#8211; match against &#8220;dog house&#8221;<\/p>\n<p><strong>Quantifers + grouping<\/strong><br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n(?:NaN)+<br \/>\n&#8211; match against &#8220;NaNNaNNaNNaNNaN&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brian Friesen&#8217;s talk on Regular Expressions was probably my favorite of the conference. You gotta admire a guy who builds a regular expression engine to properly demo and train folks up on the &#8216;devil&#8217;s language&#8217; (as I and others I&#8217;ve known have called it)&#8230; Folks that hate regex and those that live and breathe the &hellip; <a href=\"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation<\/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":[4,17],"tags":[48,45,46,47,43,44],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-development","category-javascript","tag-filtering","tag-matching","tag-patterns","tag-programming","tag-regex","tag-regular-expression"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014\u2032s-regular-expressions-presentation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design\" \/>\n<meta property=\"og:description\" content=\"Brian Friesen&#8217;s talk on Regular Expressions was probably my favorite of the conference. You gotta admire a guy who builds a regular expression engine to properly demo and train folks up on the &#8216;devil&#8217;s language&#8217; (as I and others I&#8217;ve known have called it)&#8230; Folks that hate regex and those that live and breathe the &hellip; Continue reading Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014\u2032s-regular-expressions-presentation\/\" \/>\n<meta property=\"og:site_name\" content=\"Minotaur Design\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-23T00:45:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-23T00:46:25+00:00\" \/>\n<meta name=\"author\" content=\"minoblogger\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"minoblogger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/\"},\"author\":{\"name\":\"minoblogger\",\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#\\\/schema\\\/person\\\/0a7e35e42a4936a2196bb0e9d1506725\"},\"headline\":\"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation\",\"datePublished\":\"2014-07-23T00:45:27+00:00\",\"dateModified\":\"2014-07-23T00:46:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/\"},\"wordCount\":623,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#\\\/schema\\\/person\\\/0a7e35e42a4936a2196bb0e9d1506725\"},\"keywords\":[\"filtering\",\"matching\",\"patterns\",\"programming\",\"regex\",\"regular expression\"],\"articleSection\":[\"Development\",\"Javascript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/\",\"url\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/\",\"name\":\"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#website\"},\"datePublished\":\"2014-07-23T00:45:27+00:00\",\"dateModified\":\"2014-07-23T00:46:25+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/2014\\\/07\\\/23\\\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/\",\"name\":\"Minotaur Design\",\"description\":\"Design, Dev, Art &amp; Leadership\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#\\\/schema\\\/person\\\/0a7e35e42a4936a2196bb0e9d1506725\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/#\\\/schema\\\/person\\\/0a7e35e42a4936a2196bb0e9d1506725\",\"name\":\"minoblogger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/wp-content\\\/uploads\\\/biopic.jpg\",\"url\":\"http:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/wp-content\\\/uploads\\\/biopic.jpg\",\"contentUrl\":\"http:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/wp-content\\\/uploads\\\/biopic.jpg\",\"width\":925,\"height\":1279,\"caption\":\"minoblogger\"},\"logo\":{\"@id\":\"http:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/wp-content\\\/uploads\\\/biopic.jpg\"},\"url\":\"https:\\\/\\\/www.minotaurdesign.com\\\/blog\\\/author\\\/minoblogger\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014\u2032s-regular-expressions-presentation\/","og_locale":"en_US","og_type":"article","og_title":"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design","og_description":"Brian Friesen&#8217;s talk on Regular Expressions was probably my favorite of the conference. You gotta admire a guy who builds a regular expression engine to properly demo and train folks up on the &#8216;devil&#8217;s language&#8217; (as I and others I&#8217;ve known have called it)&#8230; Folks that hate regex and those that live and breathe the &hellip; Continue reading Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation","og_url":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014\u2032s-regular-expressions-presentation\/","og_site_name":"Minotaur Design","article_published_time":"2014-07-23T00:45:27+00:00","article_modified_time":"2014-07-23T00:46:25+00:00","author":"minoblogger","twitter_misc":{"Written by":"minoblogger","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/#article","isPartOf":{"@id":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/"},"author":{"name":"minoblogger","@id":"https:\/\/www.minotaurdesign.com\/blog\/#\/schema\/person\/0a7e35e42a4936a2196bb0e9d1506725"},"headline":"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation","datePublished":"2014-07-23T00:45:27+00:00","dateModified":"2014-07-23T00:46:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/"},"wordCount":623,"commentCount":0,"publisher":{"@id":"https:\/\/www.minotaurdesign.com\/blog\/#\/schema\/person\/0a7e35e42a4936a2196bb0e9d1506725"},"keywords":["filtering","matching","patterns","programming","regex","regular expression"],"articleSection":["Development","Javascript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/","url":"https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/","name":"Notes from CodeStock 2014\u2032s \u201cRegular Expressions\u201d presentation - Minotaur Design","isPartOf":{"@id":"https:\/\/www.minotaurdesign.com\/blog\/#website"},"datePublished":"2014-07-23T00:45:27+00:00","dateModified":"2014-07-23T00:46:25+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.minotaurdesign.com\/blog\/2014\/07\/23\/notes-codestock-2014%e2%80%b2s-regular-expressions-presentation\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.minotaurdesign.com\/blog\/#website","url":"https:\/\/www.minotaurdesign.com\/blog\/","name":"Minotaur Design","description":"Design, Dev, Art &amp; Leadership","publisher":{"@id":"https:\/\/www.minotaurdesign.com\/blog\/#\/schema\/person\/0a7e35e42a4936a2196bb0e9d1506725"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.minotaurdesign.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.minotaurdesign.com\/blog\/#\/schema\/person\/0a7e35e42a4936a2196bb0e9d1506725","name":"minoblogger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.minotaurdesign.com\/blog\/wp-content\/uploads\/biopic.jpg","url":"http:\/\/www.minotaurdesign.com\/blog\/wp-content\/uploads\/biopic.jpg","contentUrl":"http:\/\/www.minotaurdesign.com\/blog\/wp-content\/uploads\/biopic.jpg","width":925,"height":1279,"caption":"minoblogger"},"logo":{"@id":"http:\/\/www.minotaurdesign.com\/blog\/wp-content\/uploads\/biopic.jpg"},"url":"https:\/\/www.minotaurdesign.com\/blog\/author\/minoblogger\/"}]}},"_links":{"self":[{"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":2,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.minotaurdesign.com\/blog\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}