<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged regexp</title>
<link>https://ask.clojure.org/index.php/tag/regexp</link>
<description></description>
<item>
<title>regular expression with Classes for Unicode scripts, blocks, categories and binary properties</title>
<link>https://ask.clojure.org/index.php/14513/regular-expression-classes-unicode-categories-properties</link>
<description>&lt;p&gt;In Clojure, the following expression works fine:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(re-matches #&quot;\p{Lu}&quot; &quot;Á&quot;) ;; =&amp;gt; &quot;Á&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But in Clojurescript, it returns &lt;code&gt;nil&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It is not that Javascript doesn't support that kind of Unicode classess, but you have to activate them explicitly, whether in Java, they are activated by default.&lt;/p&gt;
&lt;p&gt;E.g. In Javascript, the following code returns true:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/\p{Lu}/u.test(&quot;Á&quot;) // =&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But if I omit the Unicode flag (&lt;code&gt;/u&lt;/code&gt;) I get false:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/\p{Lu}/.test(&quot;Á&quot;) // =&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I think this is probably because Clojure Script doesn't activates the Unicode flag for us.&lt;/p&gt;
&lt;p&gt;If that the case, I think consistency between Clojurescript and Clojure could benefit a lot if the flag is activated by default.&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14513/regular-expression-classes-unicode-categories-properties</guid>
<pubDate>Tue, 22 Apr 2025 15:39:14 +0000</pubDate>
</item>
<item>
<title>What are the differences between JS and CLJS regular expressions?</title>
<link>https://ask.clojure.org/index.php/9359/what-are-the-differences-between-cljs-regular-expressions</link>
<description>&lt;p&gt;I have this valid JavaScript regular expression:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&amp;amp;=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&amp;amp;=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&amp;amp;;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;(matching URLs)&lt;/p&gt;
&lt;p&gt;Turns out it's not a valid CLJS one. It errors with:&lt;/p&gt;
&lt;p&gt;&lt;code&gt; #object[SyntaxError SyntaxError: unterminated parenthetical]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;changit it to:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;(def re #&quot;^((([A-Za-z]{3,9}:(?://)?)(?:[\-;:&amp;amp;=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&amp;amp;=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:/[\+~%/\.\w\-_]*)?\??(?:[\-\+=&amp;amp;;%@\.\w_]*)#?(?:[\.\!/\\\w]*))?)$&quot;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;(notice unescaped &lt;code&gt;/&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;works.&lt;/p&gt;
&lt;p&gt;Is it a CLJS bug? &lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9359/what-are-the-differences-between-cljs-regular-expressions</guid>
<pubDate>Thu, 04 Jun 2020 09:56:34 +0000</pubDate>
</item>
<item>
<title>regex equality</title>
<link>https://ask.clojure.org/index.php/8566/regex-equality</link>
<description>&lt;p&gt;How to check regexp equality in nested structures?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(= #&quot;.&quot; #&quot;.&quot;) ;; #=&amp;gt; false
(= [#&quot;.&quot;] [#&quot;.&quot;]) ;; #=&amp;gt; false
(= [&quot;.&quot;] [&quot;.&quot;]) ;; #=&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I believe that a regexp is a value object.&lt;br&gt;
So two regexp are equal if they equals literally.&lt;/p&gt;
&lt;p&gt;Is it possible to update &lt;code&gt;=&lt;/code&gt; function for regexp equality support?&lt;/p&gt;
&lt;p&gt;Maybe like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defprotocol IEquals
 (equals [a b]))

(extend-protocol IEquals
  Object
  (equals [a b] (.equals a b))
  
  Pattern
  (equals [a b]
    (and
      (instance? Pattern b)
      (= (str a) (str b))) 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And &lt;code&gt;clojure.lang.Util.equiv&lt;/code&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Util.java#L33&quot;&gt;uses&lt;/a&gt;&lt;br&gt;
&lt;code&gt;IEquals#equals&lt;/code&gt; instead of &lt;code&gt;Object#equals&lt;/code&gt;.&lt;br&gt;
But I down know how to call protocol method from &lt;code&gt;clojure.lang.Util&lt;/code&gt;.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8566/regex-equality</guid>
<pubDate>Sat, 07 Sep 2019 14:03:23 +0000</pubDate>
</item>
</channel>
</rss>