erakis
erakis

Reputation: 60

Regular expression (extract key/value pairs)

I'm trying to extract a list (match) of key/value pairs from a string. Ex :

PATH_1:"/", PATH_2:"/OtherPath", TODAY:"2016-06-27",XYZ :"1234"

This should give :

      Key            Value
      PATH_1         /
      PATH_2         /OtherPath
      TODAY          2016-06-27
      XYZ            1234

Here is what I have so far as regex :

((?:"[^"]*"|[^:,])*):((?:"[^"]*"|[^:,])*)

This is well working except that when I'm adding a path having a '\'. Ex :

PATH_1:"c:\", PATH_2:"c:\OtherPath", TODAY:"2016-06-27" 

I don't know how to instruct to regex expression to jump over semi-colon when found inside double quote sequence. Hope someone can help me.

PS : I'm using QT.

Best regards,

Upvotes: 1

Views: 5806

Answers (1)

Will Barnwell
Will Barnwell

Reputation: 4089

https://regex101.com/r/vB1rS1/2

It seems that just removing the : from the last [] may do it if the quotes are being removed.

((?:"[^"]*"|[^:,])*):((?:"[^"]*"|[^,])*)

Upvotes: 1

Related Questions