Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

I have this valid JavaScript regular expression:


(matching URLs)

Turns out it's not a valid CLJS one. It errors with:

#object[SyntaxError SyntaxError: unterminated parenthetical]

changit it to:

(def re #"^((([A-Za-z]{3,9}:(?://)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:/[\+~%/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!/\\\w]*))?)$")

(notice unescaped /)


Is it a CLJS bug?

2 Answers

+1 vote

The Javascript sample in the question uses / to delimit the expression. That's not the only way to do it. Using / as the delimiter naturally requires escaping a literal / in the pattern.

I wonder whether you'll get the same result if you delimit the regex in another way, e.g., new RegExp('...');

0 votes

you can play with cljs compiler here


Also, i had some issues around encoding and regexp. Be sure that your HTML Encoding is UTF-8.

Thanks @Enzzo. The problem is all of this was in the REPL :)