Regular expression: Match lonely double quotes
I am looking for a regular expression that matches lonely double quotes, i.e.
abc" // <-- match
abc"" // <-- no match
Based on an example replacing & with
&from QRexExp, I tried:
But that does not even match a lonely double quote.
Where have I gone wrong?
To ensure your double quote is single you need a lookahead and a lookbehind condition. In this case QRegExp is not the right tool. You need to switch to QRegularExpression and use
Thank you for the hint. Strangely, I had looked through the QRegularExpression help file for lookahead, but could not find anything. Given the complexity of the class, I probably gave up too early :-)
QRegularExpression's regexp engine is PCRE so you should be able to use features from it.
There's also the regular expression tool that you can build and use to test your regular expressions.