Question

I'd like to filter a command like with a QRegExp

/path/to/executable --long-parameter -s /path/which/has/a/space/and/a/dash/\ -end

I try to remove all the parameters that start with - and the program name (/path/to/executable)

QString str(...);
str.remove(QRegExp("^\\S*")).remove(QRegExp("\\s-\\S*")).trimmed(); 

This removes the parameters, but if there is /a/dash/\ -end, this will be treated as a parameter, when it should be left, since the space is preceded with a backslash. Is there any way to handle it?

/path/to/executable is not the program executed - it's just a string.

Was it helpful?

Solution

Why don't you handle them as a QStringList?

You can use QString::split(...) method to split it in tokens (strings, blank space separated), and then it would be trivial to

  • check wether the first character of each string is a dash (or whatever other check) and remove it(or do any operation you want).

  • remove first string (namely the path to the executable as you shown)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top