Reputation: 35398
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("\\b\\(\\?\\?\\)\\b");
but even this is not matching it... Can you help me with this?
Thanks f.
Upvotes: 0
Views: 512
Reputation: 336078
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|$)");
Upvotes: 3
Reputation: 223
You could try with \B
instead of \b
:
QRegExp("\\B\\(\\?\\?\\)\\B");
Upvotes: 0