开发者

QRegexp for (??)

I'm fighting for some time to create a QRegExp for matching the string (??) (ie: an opening parantheses, two question marks and a closing parantheses and this should be a separate word, so before and after this can be spaces, tab, newline), The closest I came up with is QRegExp("开发者_Python百科\\b\\(\\?\\?\\)\\b"); but even this is not matching it... Can you help me with this?

Thanks f.


I don't know QRegexp, but \b only matches between alphanumeric and non-alphanumeric characters, so your regex would match (??) only if it was directly surrounded by alnums (like abc(??)123).

So you need a different approach. Hoping QRegexp supports lookaround, you could use

QRegExp("(?<=\\s|^)\\(\\?\\?\\)(?=\\s|$)");

so the regex checks if there is whitespace or start/end of string before/after (??).

If that doesn't work, you'll have to match the whitespace explicitly:

QRegExp("(?:\\s|^)\\(\\?\\?\\)(?:\\s|$)");


You could try with \B instead of \b:

QRegExp("\\B\\(\\?\\?\\)\\B");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜