Results 1 to 2 of 2

Thread: help on qregexp

  1. #1
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default help on qregexp

    hello~

    I have a string like following,

    "%aaa\nbbb"

    and I want to replace "%aaa" to "x".

    Here is my code.

    QString text = "%aaa\nbbb";
    QRegExp rx = "\\b%aaa";
    text.replace( rx, "x" );
    qDebug( "%s", qPrintable( text ) );

    Output:
    %aaa\nbbb

    Unfortunately, "%aaa" never changed.
    If I remove "%" character then that is done as I wants it done.

    I don't know how can I replace strings start with "%" or "$".

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: help on qregexp

    I don't have the documentation in front of me, but I'd guess you have to escape special characters. If you want to match a literal '%', you likely have to use '\%'.

Similar Threads

  1. Help on QRegExp please
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2010, 06:57
  2. QRegExp
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2008, 18:44
  3. QRegExp help
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 10:07
  4. QRegExp
    By szczav in forum Qt Programming
    Replies: 4
    Last Post: 19th June 2007, 20:07
  5. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 00:13

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.