There is a line example:
text a b c text "text text1 text2" text d e f
I need to replace all spaces that are inside quotes. This can be solved with simpler string operations, but I would like to solve it with QRegExp (Qt 5).
After processing, I want to get a result like this
text a b c text "text_text1_text2" text d e f
C++ code with Qt:
QString str = QString("text a b c text \"text text1 text2\" text d e f");
qDebug() << str.replace(QRegExp("\"(.+)\""), QString("_"));
The pattern correctly finds the quoted string, but replaces it entirely. How do I replace only spaces? I found a solution, but it is for JavaScript, can I adapt it for Qt?
str.replace(/"[^"]*"/g, match => match.replace(/ /g, "_"));
Thanks!