将 QRegularExpression 应用于句子时避免使用 \r

Avoid the \r when applying a QRegularExpression to a sentence

我提取了以下句子:

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

来自以下行:

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.

使用这个 QRegularExpression:

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

然而,输出是:

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

\r 的存在很正常,因为我正在使用的行是写在文本文件中的(Windows 8.1 操作系统)。

你知道如何在结果输出中不带“\r”的情况下提取句子吗?我真的不知道。

非常感谢您的帮助

您可以使用 negated character class [^\r\n]:

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

[^\r\n]* 子模式匹配 \r\n 以外的零个或多个字符。