0

Why does clojure.string/replace not match the \"[^\"]+\" pattern while re-seq does?

(re-seq #"\"[^\"]+\"" "ab,\"helo,bro\",yo")
=> ("\"helo,bro\"")       

(clojure.string/replace "ab,\"helo,bro\",yo" #"\"[^\"]+\”" "") 
=> "ab,\"helo,bro\",yo" 

I would expect replace to delete the matched pattern. What am I missing here?

Thanks for insight.

1 Answer 1

2

Your regex are (probably unintentionally) different: in the replace option you used \” instead of \".

If you use the same exact regex it will work as expected:

(def r #"\"[^\"]+\"")

(re-seq r "ab,\"helo,bro\",yo")
=> ("\"helo,bro\"")

(clojure.string/replace "ab,\"helo,bro\",yo" r "") 
=> "ab,,yo"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.