Results 1 to 4 of 4

Thread: RegExp Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    43
    Thanks
    14

    Default RegExp Question

    Hello! I'm trying to figure out regexp for a line that contains starts in itself. For example some of the lines may start with ***HELLO and then continue with something else where stars are the actual stars symbols:

    !HELLO - This is the first line
    (HELLO) - Thi is is the second line
    ***HELLO - is the third line
    HELLO - This is the fourth line
    etc.

    In this text I need to locate line # 3. How can I do it with the regexp? I have tried:

    Qt Code:
    1. QRegExp rx("***HELLO*");
    2. rx.setPatternSyntax(QRegExp::Wildcard);
    3. statLineIndex = statFile.indexOf(rx);
    4. QMessageBox::about(0, "test", QString::number(statLineIndex));
    To copy to clipboard, switch view to plain text mode 
    but, of course I keep getting first and second line and can't deffirentiate the starts, first three mean the actual star symbols and the last one is any characters. How do I diffirentiate those?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: RegExp Question

    You have to escape the stars with a backslash! and for your case better split the text into lines (QStringList), loop through the list and look if they start with an asterisk. using startsWith().

    EDIT: And you have to put a "." before the last asterisks.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: RegExp Question

    ...and don't use the Wildcard semantics.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Feb 2008
    Posts
    43
    Thanks
    14

    Default Re: RegExp Question

    Thank you very much. That worked for me just fine.

Similar Threads

  1. RegExp
    By pucara_faa in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2009, 13:41
  2. Simple RegExp Question...
    By jared.carlson23 in forum Newbie
    Replies: 1
    Last Post: 4th July 2008, 14:10
  3. IPAddress Validator RegExp
    By user_mail07 in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2008, 02:36
  4. RegExp question
    By high_flyer in forum General Programming
    Replies: 1
    Last Post: 26th August 2007, 18:23
  5. Quick RegExp question
    By stealth86 in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2007, 08:23

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
  •  
Qt is a trademark of The Qt Company.