Sunday, 15 September 2013

Java regex replacing double and single quotes -



Java regex replacing double and single quotes -

i beingness fed string looks like:

"lang":"fr","fizz":"1","buzz":"thank much."

the real string much long follows pattern of comma-delimited "key":"value" pairs. strip out double-quotes around keys, , replace double-quotes surrounding alll values single-quotes, string this:

lang:'fr',fizz:'1',buzz:'thank much.'

my best attempt:

kvstring = kvstring.replaceall("\"*\":", "*:"); kvstring = kvstring.replaceall(":\"*\"", ":'*'"); system.out.println(kvstring);

when run kvstring looking like:

"lang*:'*'fr","fizz*:'*1","buzz*:'*thank much."

can spot i'm going wrong? in advance.

string str = "\"lang\":\"fr\",\"fizz\":\"1\",\"buzz\":\"thank much.\""; system.out.println(str.replaceall ("\"([^\"]*)\":\"([^\"]*)\"", "$1:'$2'"));

java regex

No comments:

Post a Comment