0

我有一个 QString,我想删除 [1]、[123]、[4556]

    QString myStr= "aaa bbb ccc .[1]";
    myStr = myStr.remove(QRegExp("\[\[0-9]\]");

但它不工作,任何想法?

4

2 回答 2

0

This is what you need:

a.remove(QRegExp("\\[[0-9]+\\]"));

First, you need double escape sequences around the outer square brackets in order to specify that those will actually show up in your string and then you need to specify the range that you want to match [0-9] and the fact that this range may show up once or more +.

于 2013-07-17T07:14:22.730 回答
0

您的 QRegExp 不起作用。第一个 QT 要求您根据您想要实现的目标对某些字符进行双重转义。其次,你不能逃避你的范围括号。您需要对要匹配的括号进行双重转义,而对于范围括号则不需要转义:

QRegExp("\\[[0-9]\\]");
于 2013-07-17T06:46:40.563 回答