{"id":187,"date":"2009-02-13T00:00:23","date_gmt":"2009-02-13T07:00:23","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=770"},"modified":"2009-02-13T00:00:23","modified_gmt":"2009-02-13T07:00:23","slug":"split-before-i-knew-about-reg-exp","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=187","title":{"rendered":"split() hacks &#038; RegExp"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar path:String = &quot;section\/home.swf&quot;;\r\n\r\nvar deepLinkValue:String = path.split(&quot;\/&quot;)&#x5B;1].split(&quot;.swf&quot;)&#x5B;0];\r\n\r\ntrace(deepLinkValue);\r\n\/*outputs:\r\nhome\r\n*\/\r\n<\/pre>\n<p>As a primarily self taught programmer there was a time when I didn&#8217;t know what a regular expression was. There was also a time when ActionScript didn&#8217;t have them (you had to use a library). Sometimes when I&#8217;m in a rush I still do weird things like the above instead of regular expressions&#8230; pretty nasty I know. <\/p>\n<p>Here are two different regular expressions that do the same thing:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar path = &quot;section\/home.swf&quot;\r\n\r\ntrace(path.match(\/w+(?=.)\/))\r\n\/*outputs:\r\nhome\r\n*\/\r\n \r\ntrace(path.replace(\/.+\/|..+\/g, &quot;&quot;))\r\n\/* also outputs:\r\nhome\r\n*\/\r\n<\/pre>\n<p>Actually, I&#8217;d be curious to see other regular expressions that only return one value (not an array) that achieve this same thing&#8230; feel free to post of a comment if you can think of one&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var path:String = &quot;section\/home.swf&quot;; var deepLinkValue:String = path.split(&quot;\/&quot;)&#x5B;1].split(&quot;.swf&quot;)&#x5B;0]; trace(deepLinkValue); \/*outputs: home *\/ As a primarily self taught programmer there was a time when I didn&#8217;t know what a regular expression was. There was also a time when ActionScript didn&#8217;t have them (you had to use a library). Sometimes when I&#8217;m in a rush I still [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,21],"tags":[3,4],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-string-manipulation","category-strings","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}