Permalink
Browse files

* src/cljs/cljs/core.cljs: CLJS-116: re-pattern supports flags

  • Loading branch information...
swannodette committed Feb 5, 2012
1 parent d9190cb commit 65a9d4fa91f195b5ef7c274b2d4ce8661848a2a6
Showing with 3 additions and 1 deletion.
  1. +2 −1 src/cljs/cljs/core.cljs
  2. +1 −0 test/cljs/cljs/core_test.cljs
View
@@ -2839,7 +2839,8 @@ reduces them without incurring seq initialization"
(defn re-pattern
"Returns an instance of RegExp which has compiled the provided string."
[s]
- (js/RegExp. s))
+ (let [[_ flags pattern] (re-find #"^(?:\(\?([idmsux]*)\))?(.*)" s)]
+ (js/RegExp. pattern flags)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Printing ;;;;;;;;;;;;;;;;
@@ -516,6 +516,7 @@
(assert (= (re-matches (re-pattern "foo.*") "foo bar foo baz foo zot") "foo bar foo baz foo zot"))
(assert (= (re-seq (re-pattern "foo") "foo bar foo baz foo zot") (list "foo" "foo" "foo")))
(assert (= (re-seq (re-pattern "f(.)o") "foo bar foo baz foo zot") (list ["foo" "o"] ["foo" "o"] ["foo" "o"])))
+ (assert (= (re-matches (re-pattern "(?i)foo") "Foo") "Foo"))
;; destructuring
(assert (= [2 1] (let [[a b] [1 2]] [b a])))

0 comments on commit 65a9d4f

Please sign in to comment.