2

I am currently trying to extract the following sentence:

This is a rectangle. Its height is 193, its width is 193 and the word number is 12.

from the following line:

ID: 1 x: 1232 y: 2208 w: 193 h: 390 wn: 12 ln: 13 c: This is a rectangle. Its height is 193, its width is 193 and the word number is 12 !

I have to do this using QRegularExpressions. Therefore, my code is as following:

regularExpression.setPattern("[c:](?:\\s*)$");
QRegularExpressionMatch match = regularExpression.match("ID: 2 x: 845 y: 1633 w: 422 h: 491 wn: 78 ln: 12 c: qsdfgh");
if (match.hasMatch()) {
    QString id = match.captured(0);
    qDebug()<<"The annotation is:"<<id;
    return id;
}
return 0;

However, it does not work at all and I do not understand why (maybe my regular expression is not correct).I am stuck in this problem from several days now.

Could you help me please ?

Dave_Dev
  • 303
  • 1
  • 12

1 Answers1

1

Use following regex to parse everything after c: and to also remove possible white space from the beginning of the string:

regularExpression.setPattern("c:\s*(.*$)");
Simo Erkinheimo
  • 1,347
  • 9
  • 17