replace( QRegularExpression(".*"), "a:\folder\1-file"))
-
I am not sure that it is what you want but try use double baskslashes to avoid captured by QRE.
replace( QRegularExpression(".*"), "a:\\folder\\1-file") )
-
@StevenG
Firstly, your literal string is wrong, this is just C++ 101. To even get something vaguely presentable you needreplace( QRegularExpression(".*"), "a:\\folder\\1-file"))
If you don't know the rules for protecting backslashes in C strings you should read up on them.
Secondly it's not possible to give a correct answer to your question without knowing what the
replace()
method is. You choose to ask a question without even telling us that. There is noQRegularExpression::replace()
, so who knows.not a placeholder for the captured( 1) from
What capture? There is no capture/regular expressioning going on, at least not without know what
replace()
is....I will charitably assume you are talking about the
replace()
method ofQString
, https://doc.qt.io/qt-5/qstring.html#replace-12.I agree there is a problem: the docs state only
For regular expressions containing capturing groups, occurrences of
\1
,\2
, ..., in after are replaced with the string captured by the corresponding capturing group.without telling you how you can avoid that. However, they do state "For regular expressions containing capturing groups". Your reg exp,
.*
, does not contain any capturing groups, so hopefully this will simply not apply and\1
will be treated as literal. So, have you actually tried it (as corrected above) to see what happens?Furthermore, reg ex
.*
should match the whole string. In that case, won't it replace the whole string witha:\folder\1-file
? And in that case, what's the point of doing any reg ex replace?!