I have a string such as this…
"test_test_test":"Hello \"Hello\" Hello","Oh_yea_oh_yea","Hi there buddy"
I want to grab
"test_test_test":"Hello \"Hello\" Hello"
So far my regex is this…
"test_test_test":
This would grab the key and colon. I will always know what "test_test_test" is, I just won’t know what the value is after the colon. It would be easy if I knew there wouldn’t be escaped quotations inside the quotations themselves, but there are. Thanks!
EDIT:
There can be commas inside, and there cannot be a quotation that’s not escaped inside.
My idea is something along the lines of…
"test_test_test":"[^(",)]*
In my head, this says keep going until you find the single quotation followed by a comma, (“,) then stop. However that doesn’t work above.
This is the RAW regex. You may need to add more escape if you put into string or include a separator.
If you need flexible spacing:
The key part is here:
(?:[^"\\]|\\[\\"])*. It will match 0 or more of: non-quote-or-backslash, or escaped quote\"or escaped backslash\\.The regex above is still imprecise: the content in the quoted string is allowed to span multiple lines. Whether it is good or not depends on the grammar for the quoted string. However, multi-line quoted string in the languages I have seen usually doesn’t take the form described in my regex.
The regex also treats the quoted string
"\n"as invalid. You can easily modify the regex a bit to accommodate those cases, though.