{"id":7577,"date":"2016-03-24T10:07:35","date_gmt":"2016-03-24T15:07:35","guid":{"rendered":"http:\/\/bobbeaty.com\/wp\/?p=7577"},"modified":"2016-03-28T06:36:38","modified_gmt":"2016-03-28T11:36:38","slug":"case-insensitive-regex-for-clojure","status":"publish","type":"post","link":"https:\/\/bobbeaty.com\/wp\/archives\/7577","title":{"rendered":"Case Insensitive Regex for Clojure"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bobbeaty.com\/wp\/wp-content\/uploads\/2010\/04\/Clojure.jpg\" alt=\"Clojure.jpg\" title=\"Clojure.jpg\" border=\"0\" width=\"125\" height=\"125\" style=\"float:right;\" \/><\/p>\n<p>One of the things that I find I need to do every now and then is to have a <em>case-insensitive<\/em> regex pattern match in clojure, and I always have to spend 15 mins looking for it on the net. Not that it's hard to find, but it's 15 mins, and if I know I wrote about it here, then I can do a much quicker search, and get the same answer.<\/p>\n<p>The key is that the Java regex parser recognizes two interesting options to the source for the regex: <tt>(?i)<\/tt> and <tt>(?iu)<\/tt>. The first, <tt>(?i)<\/tt>, is the flag to indicate that the entire regex is to be considered case-insensitive. The second, <tt>(?iu)<\/tt> is for unicode support.<\/p>\n<p>So how's it work?<\/p>\n<pre class=\"clojure\" style=\"font-family:monospace;\">  <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #b1b100;\">re-find<\/span> #<span style=\"color: #ff0000;\">&quot;Cook&quot;<\/span> <span style=\"color: #ff0000;\">&quot;This is how to cook.&quot;<\/span><span style=\"color: #66cc66;\">&#41;<\/span>\n  <span style=\"color: #66cc66;\">=&gt;<\/span> nil\n&nbsp;\n  <span style=\"color: #66cc66;\">&#40;<\/span><span style=\"color: #b1b100;\">re-find<\/span> #<span style=\"color: #ff0000;\">&quot;(?i)Cook&quot;<\/span> <span style=\"color: #ff0000;\">&quot;This is how to cook.&quot;<\/span><span style=\"color: #66cc66;\">&#41;<\/span>\n  <span style=\"color: #66cc66;\">=&gt;<\/span> <span style=\"color: #ff0000;\">&quot;cook&quot;<\/span><\/pre>\n<p>It's simple and easy, and typically saves you from calling <tt>lcase<\/tt> on the string before the regex test.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the things that I find I need to do every now and then is to have a case-insensitive regex pattern match in clojure, and I always have to spend 15 mins looking for it on the net. Not that it&#8217;s hard to find, but it&#8217;s 15 mins, and if I know I wrote [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,4],"tags":[],"class_list":["post-7577","post","type-post","status-publish","format-standard","hentry","category-clojure-coding","category-open-source-software"],"_links":{"self":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/7577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/comments?post=7577"}],"version-history":[{"count":2,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/7577\/revisions"}],"predecessor-version":[{"id":7579,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/7577\/revisions\/7579"}],"wp:attachment":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/media?parent=7577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/categories?post=7577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/tags?post=7577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}