QRegularExpression
-
Hi,
I would like to extract some QString
/* My QString = "Lu 01/10/2023;2.60 m;4h16B;8h27M;16h46B;21h02M" */ static const QRegularExpression re("\\d.\\d{1,2}"); QRegularExpressionMatch match = re.match(ligne1); qDebug() << re.pattern(); if (match.hasMatch()) { a = match.captured(1); // 2.60 } qDebug() << "a =" << a; exit(0);even if I use re("\d.");
or re("^\d$"); or anything else, nothing works.I do not anderstand.
-
Hi,
I would like to extract some QString
/* My QString = "Lu 01/10/2023;2.60 m;4h16B;8h27M;16h46B;21h02M" */ static const QRegularExpression re("\\d.\\d{1,2}"); QRegularExpressionMatch match = re.match(ligne1); qDebug() << re.pattern(); if (match.hasMatch()) { a = match.captured(1); // 2.60 } qDebug() << "a =" << a; exit(0);even if I use re("\d.");
or re("^\d$"); or anything else, nothing works.I do not anderstand.
@Morgatte
What is it you want but don't get?? Your question is not clear. Do you get2.60or do you want2.60but not get it? I would assume it would match the1/10which comes early in the string? Or maybe2023ifcaptured(1)is the second match. Actually you have no capturing groups, so I'm not surecaptured(1)would ever return anything.Could you please actually
qDebug() << ligne, and could you state whether it goes into theif(does it match? how many captures are in it?) and could you show the output fromqDebug() << "a =" << a;. You can see the output, we cannot, we are not mind readers!In any case, since you intend your reg ex to capture a literal
.between the digits I assume it should read"\\d\\.\\d{1,2}"