Results 1 to 5 of 5

Thread: QRegExp help

  1. #1
    Join Date
    Mar 2016
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default QRegExp help

    I would like to remove all lines from a QString that have text and keep the ones that are numbers.

    Prior to running a regexp my QString output be as so:
    Qt Code:
    1. hello
    2. 1
    3. world
    4. 2
    To copy to clipboard, switch view to plain text mode 

    if I ran something like
    Qt Code:
    1. QString.remove(QRegExp("(^[a-z]*\\n$)"))
    To copy to clipboard, switch view to plain text mode 
    my QString output would be:

    Qt Code:
    1. 1
    2. 2
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp help

    So? Have you tried the solution you propose? Did you get the expected result?

  3. #3
    Join Date
    Mar 2016
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: QRegExp help

    Quote Originally Posted by yeye_olive View Post
    So? Have you tried the solution you propose? Did you get the expected result?
    No. I ended up just convert it to a QStringList and doing it line by line. The only reason I wanted to do it with a regexp was to save some lines of code.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp help

    Well, that would have only saved one line of code compared to using QString::split() and QStringList::filter()

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRegExp help

    Obviously not being paid per line of code.

Similar Threads

  1. help on qregexp
    By sanqt in forum Newbie
    Replies: 1
    Last Post: 20th February 2011, 16:39
  2. QRegExp Help
    By ToddAtWSU in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2010, 15:35
  3. QRegExp
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2008, 18:44
  4. QRegExp help
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 10:07
  5. QRegExp
    By szczav in forum Qt Programming
    Replies: 4
    Last Post: 19th June 2007, 20:07

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.