In a Qt project I'm having to split a QString by the following separators
在Qt项目中,我必须使用以下分隔符分割QString
- Feat.
- 的壮举。
- feat.
- 的壮举。
- Feat
- 的壮举
- feat
- 的壮举
- Featuring
- 特色
- featuring.
- 特色。
- Featuring
- 特色
- featuring
- 特色
My best try was (?: [Ff]eat[.]? )|(?: [[Ff]eaturing][.]?)
as in
我最好的尝试是(?(Ff):吃[]?)|(?:[(Ff)eaturing][]?)
QRegExp xp("(?: [Ff]eat[.]? )|(?: [[Ff]eaturing][.]? )");
QString str = "Eminem Feat. Rihanna";
QStringList list = alist.split(xp);
The above lines of codes doesn't work for me. This is a simple RegExp problem. I'm just too confused. Any sort of help or suggestion would be awesome!
上面的代码行对我不起作用。这是一个简单的RegExp问题。我太糊涂了。任何形式的帮助或建议都是很棒的!
2 个解决方案
#1
2
You have an extra character class in the 2nd part of regex.
在regex的第二部分中有一个额外的字符类。
Try using this:
试着用这个:
QRegExp xp("(?: [Ff]eat[.]? )|(?: [Ff]eaturing[.]? )");
And you can combine both of them in one pattern, using ?
quantifier, and you don't need the outermost non-capturing group.
你可以把它们结合在一起,使用?量词,你不需要最外面的非捕获组。
QRegExp xp(" [Ff]eat(?:uring)?[.]? ");
#2
1
Try this pattern:
试试这个模式:
(?: [fF]eat(?:uring)?\.? )
Or replace the spaces with word boundaries
或者用单词边界替换空格
(?:\b[fF]eat(?:uring)?\.?\b)
#1
2
You have an extra character class in the 2nd part of regex.
在regex的第二部分中有一个额外的字符类。
Try using this:
试着用这个:
QRegExp xp("(?: [Ff]eat[.]? )|(?: [Ff]eaturing[.]? )");
And you can combine both of them in one pattern, using ?
quantifier, and you don't need the outermost non-capturing group.
你可以把它们结合在一起,使用?量词,你不需要最外面的非捕获组。
QRegExp xp(" [Ff]eat(?:uring)?[.]? ");
#2
1
Try this pattern:
试试这个模式:
(?: [fF]eat(?:uring)?\.? )
Or replace the spaces with word boundaries
或者用单词边界替换空格
(?:\b[fF]eat(?:uring)?\.?\b)