1

I have extracted the following sentence :

Very important point. It should be discussed in our next meeting.

from the following line:

ID: 1 x: 1202 y: 2453 w: 242 h: 459 wn: 13 ln: 12 c: Very important point. It should be discussed in our next meeting.

using this QRegularExpression:

 regularExpression.setPattern("(?<=\\s)c:\\s?(.*)$");

However, the output is:

Very important point. It should be discussed in our next meeting.\r

The presence of the \r is quite normal because the line I am working with is written in a text file (Windows 8.1 Operating System).

Do you know how to extract the sentence without having the "\r" in the resulting output ? I really have no idea.

Thank you so much for your help

Dave_Dev
  • 303
  • 1
  • 12

1 Answers1

2

You can achieve that using a negated character class [^\r\n]:

regularExpression.setPattern("(?<=\\s)c:\\s?([^\r\n]*)");
                                             ^^^^^^^^

The [^\r\n]* subpattern matches zero or more characters other than \r and \n.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Hi, it works like a charm. Thank you so much for your help, I appreciate :) – Dave_Dev Dec 28 '15 at 19:06
  • 1
    You are welcome. The negated character classes are very helpful in Qt, where lazy quantifiers are missing (you need to set laziness using a regexp `setMinimal` method or using a flag) and `.` matches any character including a newline. – Wiktor Stribiżew Dec 28 '15 at 19:08
  • Ok, thank you so much for the hint ;) I'll take it into account next time :) – Dave_Dev Dec 28 '15 at 19:10