Results 1 to 2 of 2

Thread: QRegExp documentation

  1. #1
    Join Date
    Nov 2011
    Location
    Karlsruhe, Germany
    Posts
    57
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default QRegExp documentation

    Hi, it must be an easy to solve problem i hope

    what is the regular expression for the pattern:

    G|xxxx - a capital letter | arbitrary word

    I used the patterns below but they failed:

    Qt Code:
    1. rule.pattern = QRegExp("\\b([A-Z])\\|([a-z])\\s");
    2.  
    3. or
    4.  
    5. rule.pattern = QRegExp("\\b([A-Z])|([a-z])\\s");
    To copy to clipboard, switch view to plain text mode 

    the thing is i have no idea how to express vertical bar in this case.
    anyone can help?

    ps: i find the documentation from QRegExp is somehow not clearly explain all the cases.
    is there any better tutorials for that?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QRegExp documentation

    Vertical bar in your code is ok, but [a-z] is not "arbitraty word", for that you can use \w+ which means "any word character one or more times":
    Qt Code:
    1. #include <QRegExp>
    2. #include <QStringList>
    3. #include <QDebug>
    4.  
    5. int main(){
    6. QRegExp rx("^([A-Z])\\|(\\w+)$");
    7. QStringList str = QStringList() << "G|word" << "_K|another" << "z|maybethis" << "P|this_one_for_sure" << "Z|!@#";
    8. foreach (QString s, str){
    9. if (rx.indexIn(s) > -1){
    10. qDebug() << rx.capturedTexts();
    11. }
    12. }
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stampede for this useful post:

    cic (30th October 2013)

Similar Threads

  1. Documentation
    By wookie1 in forum Qt Tools
    Replies: 2
    Last Post: 24th June 2014, 03:31
  2. Qt Creator Documentation need.
    By themean in forum Qt Tools
    Replies: 0
    Last Post: 7th February 2013, 11:41
  3. Qwt 6.0 documentation
    By m15ch4 in forum Qwt
    Replies: 0
    Last Post: 20th February 2011, 15:48
  4. Adding Qt's documentation to Xcode documentation browser
    By fabietto in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2007, 15:38
  5. Where is documentation for qtopiamake ???
    By burkav84 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 10th May 2007, 15:16

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.