3

I have data that will appear as dual quotation pairs like this, per line.

"Key" "Value"

Inside of these pairs there can be any character, and sometimes there comes the dreaded "" nested pair:

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

Previously I've found: "([^"]*)"\s*"([^"]*)" And this matches Key and Value to two groups:

$1 = Key
$2 = Value

But, with the nested pairs, it will only output:

$1 = superkey

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

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

Regular expression processing from QRegularExpression and c++11 Literal string:

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

I know it matches Pearl and PHP regex.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
CZauX
  • 109
  • 2
  • 9
  • 1
    How can you differentiate between nested and unnested quotes? If those inside were doubled, it would be possible. – Wiktor Stribiżew Jul 09 '15 at 06:42
  • Do you mean if it was "" nested? That is the problem currently, single quotation pairs are fine. – CZauX Jul 09 '15 at 07:38
  • Interesting question. I tried with something simple [like this](https://regex101.com/r/eD7uO2/1): `^"(.*?)"\h+"(.*)"` – Jonny 5 Jul 09 '15 at 09:53

1 Answers1

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

Try this.See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124
  • This works for one line, but degrades over multiple. https://regex101.com/r/hR7tH4/1 – CZauX Jul 09 '15 at 07:30
  • Works very well, I did a bit of editing because it would bug out if the double quote pairs were next to each other or if there were other characters after the pairs. https://regex101.com/r/aT9jV1/1 – CZauX Jul 09 '15 at 08:29
  • 1
    -I take that back, doesn't do the original purpose, but yours does, so marking it as answer, thank you. – CZauX Jul 09 '15 at 08:34