Results 1 to 5 of 5

Thread: advances search with QRegExp

  1. #1
    Join Date
    Nov 2010
    Posts
    30
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question advances search with QRegExp

    hi ..

    how I can do advances search with QRegExp..
    if i write "word(?=\s+word2)" just line 2 return true :
    1-word false
    2-word word2 true
    3-word word1 word2 false

    my questions is how can i write to "word word1 word2" be true ?

    and if write word(?!=\s+word2) "word word1 word2" is still true but how can i write to be false and only "word" be true?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: advances search with QRegExp

    Will this work for you
    Qt Code:
    1. QRegExp exp("*word*word2*");
    2. exp.setPatternSyntax(QRegExp::Wildcard);
    3.  
    4. exp.exactMatch("word") ? "true" : "false"); //false
    5. exp.exactMatch("word word2") ? "true" : "false"); //true
    6. exp.exactMatch("word word1 word2") ? "true" : "false"); //true
    7. exp.exactMatch("word word2 word1") ? "true" : "false"); //true
    8. exp.exactMatch("word0 word2 word1") ? "true" : "false"); //true
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2010
    Posts
    30
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: advances search with QRegExp

    thanks ..

    how can set unwanted word ?

    for example the like not have word4

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: advances search with QRegExp

    Here this may a better solutionfor you, without wildcards.

    Qt Code:
    1. QRegExp exp("word\\s(?!word4).*word2.*");
    2.  
    3. exp.exactMatch("word") ? "true" : "false"); //false
    4. exp.exactMatch("word word2") ? "true" : "false"); //true
    5. exp.exactMatch("word word1 word2") ? "true" : "false"); //true
    6. exp.exactMatch("word word2 word1") ? "true" : "false"); //true
    7. exp.exactMatch("word0 word2 word1") ? "true" : "false"); //false
    8. exp.exactMatch("word word4 word2 word1") ? "true" : "false"); //false
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: advances search with QRegExp

    but he want to use lookahead and match only "word".
    This is quite simple fix you excretion like this (\b means word border):
    \bword\b(?=.*\bword2\b)

Similar Threads

  1. Advanced QFileSystemModel
    By alexivanov91 in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2010, 09:23
  2. Advanced QTableView
    By jpujolf in forum Qt Programming
    Replies: 13
    Last Post: 17th April 2010, 09:15
  3. Advanced PKG Options [S60]
    By ManuMies in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 30th November 2009, 11:52
  4. Advanced use of QUiLoader
    By doberkofler in forum Newbie
    Replies: 0
    Last Post: 27th October 2009, 21:02
  5. Search for QRegExp in a QString
    By Abc in forum Qt Programming
    Replies: 6
    Last Post: 13th August 2008, 09:31

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.