Results 1 to 3 of 3

Thread: QRegExp help

  1. #1
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QRegExp help

    Hi all,
    maybe this is not only a Qt question.
    I'm using QRegExp for replace any occourrence of a word composed by one or two letters.
    I don't get what expected, what I'm doing wrong?
    thanks for any help/

    Qt Code:
    1. QString resS = QString("a la test da che da me asdf non va");
    2. resS.replace(QRegExp("[a-z]{1,2}"), "X");
    To copy to clipboard, switch view to plain text mode 

    I get this:
    X X XX X XX X X XX XX X

    instead of
    X X test X che X X asdf non X

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QRegExp help

    Try adding word boundaries:
    Qt Code:
    1. QRegExp("\\b[a-z]{1,2}\\b")
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    Lele (8th February 2008)

  4. #3
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp help

    Thanks a lot, it works!

Similar Threads

  1. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 00:13
  2. QRegExp progblem
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2006, 12:12
  3. QRegExp?
    By Marco812 in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2006, 08:31
  4. need help for my QRegExp
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 16:29
  5. Trouble parsing using simple QRegExp
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2006, 00:42

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.