The following pattern works for me with the input you provide and a few more I tested:
test(
"test \"a string\" \"string \\\" escaped\" 1 2",
"((?:[^\\s\"]+)|(?:\"(?:\\\\\"|[^\"])*\"))");
test(
"test \"a string\" \"string \\\" escaped\" 1 2",
"((?:[^\\s\"]+)|(?:\"(?:\\\\\"|[^\"])*\"))");
To copy to clipboard, switch view to plain text mode
Output of qDebug() << rx.cap(1):
testing "test "a string" "string \" escaped" 1 2" against "((?:[^\s"]+)|(?:"(?:\\"|[^"])*"))"
"test"
""a string""
""string \" escaped""
"1"
"2"
Bookmarks