Results 1 to 2 of 2

Thread: QRegExp progblem

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QRegExp progblem

    Hi,

    I have the following code, which should find all occorences of '_' which is followed by a number, and replace it with a '.' (dot).
    But nothing is being replced...
    I guess my QRegExp is wrong, but from reading the docs, I don't understand why...

    Thanks.
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. //Q_INIT_RESOURCE(application);
    4.  
    5. QApplication app(argc, argv);
    6. QRegExp re("_(?=\d+)");
    7. QFile ifile("marquard.csv");
    8. QFile ofile("marqurd_new.cvs");
    9. ifile.open(QIODevice::ReadOnly);
    10. ofile.open(QIODevice::WriteOnly);
    11. QTextStream istream(&ifile);
    12. QTextStream ostream(&ofile);
    13. QString text;
    14. istream>>text;
    15. text.replace(re,".");
    16. ostream<<text;
    17. ifile.close();
    18. ofile.close();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp progblem

    You need two backslashes:
    Qt Code:
    1. QRegExp re("_(?=\\d+)")
    To copy to clipboard, switch view to plain text mode 

    It works for me:
    Qt Code:
    1. danadam@peasant18]$ cat a.txt
    2. aaaa_3dfd
    3. danadam@peasant18]$ cat b.txt
    4. aaaa.3dfd
    To copy to clipboard, switch view to plain text mode 
    The Wheel weaves as the Wheel wills.

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

    high_flyer (6th September 2006)

Similar Threads

  1. QRegExp?
    By Marco812 in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2006, 08:31
  2. QRegExp Help; remove all html tag
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 27th July 2006, 13:40
  3. need help for my QRegExp
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 16:29
  4. Trouble parsing using simple QRegExp
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2006, 00:42
  5. IP adresses with QRegExp (Qt3)
    By jlbrd in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 13:43

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.