A regex to match a comma that isn't surrounded by quotes.

Posted by Rayne on Stack Overflow See other posts from Stack Overflow or by Rayne
Published on 2010-04-23T18:17:04Z Indexed on 2010/04/23 18:33 UTC
Read the original article Hit count: 386

Filed under:
|
|

I'm using Clojure, so this is in the context of Java regexes.

Here is an example string:

"{:a "ab,cd, efg", :b "ab,def, egf,", :c "Conjecture"}"

The important bits are the commas after each string. I'd like to be able to replace them with newline characters with Java's replaceAll method. A regex that will match any comma that is not surrounded by quotes will do.

If I'm not coming across well, please ask and I'll be happily to clarify anything.

edit: sorry for the confusion in the title. I haven't been awake very long.

String: {:a "ab, cd efg",} <-- In this example, the comma at the end would be matched, but the ones inside the quote would not.

© Stack Overflow or respective owner

Related posts about regex

Related posts about java