PDA

View Full Version : QRegexp grep for multiple keywords



gig-raf
17th February 2016, 12:00
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



regex.setPattern("<div class=\"head\">(keyword1|keyword2):</div>");
regex.setPatternOptions(QRegularExpression::DotMat chesEverythingOption);
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.

Lesiok
17th February 2016, 12:42
After compiling expresion string is : <div class="head">(keyword1|keyword2):</div> - without backslashes.
Is this what You want ?

gig-raf
17th February 2016, 20:46
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?

jefftee
18th February 2016, 04:08
You need to escape the "/" in the </div> tag like so:



regex.setPattern("<div class=\"head\">(keyword1|keyword2):<\/div>");