{"id":4283,"date":"2011-08-30T09:15:00","date_gmt":"2011-08-30T09:15:00","guid":{"rendered":""},"modified":"2026-04-18T22:50:20","modified_gmt":"2026-04-18T22:50:20","slug":"regex-in-groovy-match-characters-and-some-special-ones","status":"publish","type":"post","link":"https:\/\/hellem.org\/wblog\/?p=4283","title":{"rendered":"Regex in Groovy: Match characters and some special ones"},"content":{"rendered":"<p>I&#8217;m writing a script that validates a file with key\/value-pairs. One type of a valid value is a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Java_Naming_and_Directory_Interface\">JNDI-name<\/a>. Before the actual name it is also a whitespace. So my if-statement with the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Regular_expression\">regex<\/a> validating ended up like this<\/p>\n<p><!-- codeblock lang=\"\" line=\"1\" --><\/p>\n<pre><code>currentLine ==~ \/^.*=\\s+[A-Za-z0-9\\\/-]+\/<\/code><\/pre>\n<p><!-- \/codeblock --><\/p>\n<p>To explain it:<\/p>\n<ul>\n<li>==~ means validate true\/false, see http:\/\/groovy.codehaus.org\/Tutorial+4+-+Regular+expressions+basics<\/li>\n<li>Then the regex starts and ends with a forward slash<\/li>\n<li>^.*= means match lines with text containing any type of character ending with an equal sign (the keys)<\/li>\n<li>\\s+ means match one or more whitespaces. Should really just need to verify one and only one, but what the heck&#8230;<\/li>\n<li>[A-Za-z0-9\\\/-]+ is a character class saying match all uppercase letters, all lowercase, all numbers and also forward slashes and hyphens. Some of the names have hyphens so I needed that one to. The + sign at the end says &#8220;one or more occurences&#8221;, see the heading &#8220;Regular Expression Operators&#8221; found on the above mentioned link<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m writing a script that validates a file with key\/value-pairs. One type of a valid value is a JNDI-name. Before the actual name it is also a whitespace. So my if-statement with the regex validating ended up like this currentLine ==~ \/^.*=\\s+[A-Za-z0-9\\\/-]+\/ To explain it: ==~ means validate true\/false, see http:\/\/groovy.codehaus.org\/Tutorial+4+-+Regular+expressions+basics Then the regex starts [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"class_list":["post-4283","post","type-post","status-publish","format-standard","hentry","category-work-geek"],"_links":{"self":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4283"}],"version-history":[{"count":1,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4283\/revisions"}],"predecessor-version":[{"id":13335,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=\/wp\/v2\/posts\/4283\/revisions\/13335"}],"wp:attachment":[{"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellem.org\/wblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}