java - Parsing key value pairs using regular expression -


i've scenario have capture key value pairs string key cannot contain spaces. following constraints apply values:

  1. they can contain spaces when delimited single or double quotes.
  2. they can contain single quotes when delimited double quotes.
  3. they can contain double quotes when delimited single quotes.
  4. key value pairs separated using spaces/tabs.

single string contains key/value pairs extract (using / string delimiters simplicity):

/abc="hello how you" xyz="i'm good. how you?" pqr='using " double quotes'/ 

i parse above string , extract name/value pairs:

  1. abc="hello how you"
  2. xyz="i'm good. how you?"
  3. pqr='using " double quotes'

see demo

(\w+)=(['"])((?!\2).+?)\2 

$1 key , $3 value

while(match.find()){ //save map } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -