私は、リモート マシンでアプリケーションを実行するターミナル プログラムに取り組んでいます。Windows cmd.exe のようなコマンドを次のように渡すことができます。
"C:\random Directory\datApplication.py" "validate" -r /c "C:\anotherDirectory"
それを可能にするために、引用されたテキストを処理し、その文字列からコマンドとその引数を解析する必要があります。notepad ++で、それらにパッチを適用するためのRegExpを見つけましたが、(([^" \t\n]+)|("[^"]*"))+
機能します。Qt4.8.1
私が試した:
static const QRegExp re("(([^\" \\t\\n]+)|(\"[^\"]*\"))+");
re.matchExact(str); // str is something like shown above
qDebug() << re.capturedTexts();
そして、このコードは私を3回だけ出力し"C:\random Directory\datApplication.py"
、それ以上は何も出力しません。入力されたすべての引数を単一のオブジェクトとして出力する必要があります...
それを機能させるために何ができますか?
解決策: (リンドリアンに感謝)
const QString testText = "\"C:\\random Directory\\datApplication.py\" \"validate\" -r /c \"C:\\anotherDirectory\"";
static const QRegExp re("([^\" \\t\\n]+|\"[^\"]*\")+");
int pos = 0;
while ((pos = re.indexIn(testText)) != -1) //-i indicates that nothing is found
{
const int len = re.matchedLength();
qDebug() << testText.mid(pos,len);
pos += len;
}