QRegexp grep for multiple keywords
I have a problem with QRexep patterns. I am basically trying to match lines in a HTML tag, but I want only to match the lines that has the keyword
Code:
regex.setPattern("<div class=\"head\">(keyword1|keyword2):</div>");
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatch match = regex.match(data.data());
I want to catch the following:
<div class=\"head\">keyword1:</div>
<div class=\"head\">keyword2:</div>
but with the pattern above I get none. I have tried escaping the parentheses around my keywords, but result was the same.
has someone had similar problems, or can some one spot what I am doing wrong, can I do such a thing with QT at all?
Thanks in advance for any advice.
Re: QRegexp grep for multiple keywords
After compiling expresion string is : <div class="head">(keyword1|keyword2):</div> - without backslashes.
Is this what You want ?
Re: QRegexp grep for multiple keywords
yes, what I want are all lines like this,
<div class="head">keyword1:</div>
or
<div class="head">keyword2:</div>
the docs state that you can look for multiple keywords using the (kw1|kw2|kw3) etc. I have tried with [] and () my match is not working. Do you have a tip?
Re: QRegexp grep for multiple keywords
You need to escape the "/" in the </div> tag like so:
Code:
regex.setPattern("<div class=\"head\">(keyword1|keyword2):<\/div>");