alexanderkiel / phrase

Clojure(Script) library for phrasing spec problems.
Eclipse Public License 1.0
289 stars 8 forks source link

In the "More Complex Example", why are any slashes in the regexes removed? #1

Closed xavi closed 6 years ago

xavi commented 6 years ago

In https://github.com/alexanderkiel/phrase#more-complex-example , why this code...

(case (str/replace (str re) #"/" "")
  "\\d" "number"
  ; ...
  )

is not simply...?

(case (str re)
  "\\d" "number"
  ; ...
  )
alexanderkiel commented 6 years ago

Because in ClojureScript, (str #"\d") evaluates to "/\\d/" while in Clojure it evaluates to "\\d". I have no idea why this is the case.

xavi commented 6 years ago

I see. Thanks!

Maybe ClojureScript behavior comes from JavaScript behavior, where

(new RegExp('\\d')).toString()
// => "/\d/"