QRegex help
Unsolved
General and Desktop
-
In this example:
QStringList notFoundStrings{"0", "1"}; for (const QString &string : notFoundStrings) { QString s = QString("^.*{\\s*%1\\s*,\\s*{.*$").arg(string); QRegularExpression regex(s); text.remove(regex); }
The content of
text
is:{ 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*0$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} }, { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*1$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} }, { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*2$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} }, { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*3$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} }, { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*4$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} }, { 544, {"test|anx|fve|229,166,18,17|229,158,42,34|?|*155$18.s0zs1Us1Us1UG30o3QY7zw7zsAzs8TsMDswvww0xy0vy0zz0zzUU"} }, { 544, {"test|exi|gpg|161,166,20,22|140,140,52,54|132,135,154,68|*142$20.s00C003U00k00A003U00800000000001000A202s003U00DU00y00Ds03zU0zy0Dzk3zw0zzU8"} },
Why is it not removing all lines starting with
{ 0, ...
and{ 1, ...
?
I tested the regex here and it does work. -
@Rua3n
By default:- The RE dot
.
does not match newlines - A string containing multiple newlines is a single string to the RE
Your RE tester is feeding the lines in your test string one at a time. You are feeding the RE all the input as a single string. The RE cannot match because the first newline in the string cannot be consumed by the
.*
Try:
QRegularExpression regex(s, QRegularExpression::MultilineOption);
This will not remove lines, but it will remove the text matched leaving a vestigial
\n
- The RE dot