Results 1 to 4 of 4

Thread: QRegexp grep for multiple keywords

  1. #1
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

    Qt Code:
    1. regex.setPattern("<div class=\"head\">(keyword1|keyword2):</div>");
    2. regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
    3. QRegularExpressionMatch match = regex.match(data.data());
    To copy to clipboard, switch view to plain text mode 


    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.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegexp grep for multiple keywords

    After compiling expresion string is : <div class="head">(keyword1|keyword2):</div> - without backslashes.
    Is this what You want ?

  3. #3
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QRegexp grep for multiple keywords

    You need to escape the "/" in the </div> tag like so:

    Qt Code:
    1. regex.setPattern("<div class=\"head\">(keyword1|keyword2):<\/div>");
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. multiple word QRegExp
    By vladozar in forum Qt Programming
    Replies: 2
    Last Post: 6th December 2012, 00:07
  2. Replies: 0
    Last Post: 8th November 2010, 11:49
  3. How to use grep in Qt
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2009, 12:16
  4. Hyperlink from QT keywords to ref manual
    By xenome in forum Qt Tools
    Replies: 1
    Last Post: 11th August 2009, 22:46
  5. Highlighting the keywords in a text edit
    By divya balachandran in forum Qt Programming
    Replies: 3
    Last Post: 6th September 2008, 14:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.