Match any char inside two quote pairs including nested quotes

I have data that will display as double-quoted pairs like this on each line.

"Key" "Value"

      

These pairs can contain any character, and sometimes the dreaded "" nested pair comes up:

"Key "superkey"" ""Space" Value"

      

Earlier I found: "([^"]*)"\s*"([^"]*)"

And this matches key and value to two groups:

$1 = Key
$2 = Value

      

But, with nested pairs, it will only output:

$1 = superkey

      

Is there a way to match all characters between pairs? Example output required:

$1 = Key "superkey"
$2 = "Space" Value

      

Regular Expression Handling from QRegularExpression and C ++ 11 Literal String:

QRegularExpression(R"D("([^"]*)"\s*"([^"]*)")D");

      

I know this matches Pearl and PHP regex.

+3


source to share


1 answer


"(.*?)"[\t\r ]+"(.*?)"(?=[ ]*$)

      

Try it. Check out the demo.



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

+2


source







All Articles