RegExp flags are being dropped by `string/replace`
Description
`clojure.string/replace` accepts either a string or pattern argument to match against.
For pattern arguments, the current implementation discards the original RegExp and creates a new one: `(.replace s (js/RegExp. (.-source match) "g") replacement)`
This is killing any flags on the original pattern (case insensitivity, for example). As a result, things like `(str/replace "Foo" #"(?i)foo" "bar")` currently fail. The result is "Foo", it should be "bar".
Can I submit a patch that'll check for and preserve other (i/m/y) flags?
Thanks
Environment
None
Attachments
1
Activity
Jake McCrary
February 5, 2016 at 12:43 AM
This patch changes string/replace-all to respect flags that were set on regexp passed as an argument.
lvh
July 27, 2015 at 5:55 PM
This appears to be identical to CLJS-485, which has a patch (by someone who hasn't signed the CLA yet).
`clojure.string/replace` accepts either a string or pattern argument to match against.
For pattern arguments, the current implementation discards the original RegExp and creates a new one:
`(.replace s (js/RegExp. (.-source match) "g") replacement)`
This is killing any flags on the original pattern (case insensitivity, for example). As a result, things like `(str/replace "Foo" #"(?i)foo" "bar")` currently fail. The result is "Foo", it should be "bar".
Can I submit a patch that'll check for and preserve other (i/m/y) flags?
Thanks