Java: splitting a comma-separated string but ignoring commas in quotes

前端 未结 11 1729
广开言路
广开言路 2020-11-21 05:16

I have a string vaguely like this:

foo,bar,c;qual=\"baz,blurb\",d;junk=\"quux,syzygy\"

that I want to split by commas -- but I need to igno

11条回答
  •  深忆病人
    2020-11-21 06:08

    You're in that annoying boundary area where regexps almost won't do (as has been pointed out by Bart, escaping the quotes would make life hard) , and yet a full-blown parser seems like overkill.

    If you are likely to need greater complexity any time soon I would go looking for a parser library. For example this one

提交回复
热议问题