Results 1 to 7 of 7

Thread: How do I create QRegExp?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 18 Times in 17 Posts

    Default How do I create QRegExp?

    Hi
    I have a list of string separated by comman, such as

    "b01350,b01351,b01352,b01353,b01354,b01355,b01356, b01357,b01358,b01359
    b01360,b01361,b01362,b01363,b01364,b01365,b01366,b 01367,b01368,b01369
    b01370,b01371,b01372,b01373,b01374,b01375,b01376,b 01377,b01378,b01379
    b01380,b01381,b01382,b01383,b01384,b01385,b01386,b 01387,b01388,b01389
    b01390,b01391,b01392,b01393,b01394,b01395,b01396,b 01397,b01398,b01399"


    I would like to convert the list using QRegExp so it become "b013[5-9][0-9]"

    How do I do it?

    Thanks

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

    Default Re: How do I create QRegExp?

    Qt Code:
    1. QStringList items = str.split(",").filter(QRegExp("b013[5-9][0-9]"));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 18 Times in 17 Posts

    Default Re: How do I create QRegExp?

    Quote Originally Posted by jpn View Post
    Qt Code:
    1. QStringList items = str.split(",").filter(QRegExp("b013[5-9][0-9]"));
    To copy to clipboard, switch view to plain text mode 
    Actual, I need the filter expression...

    that is, I need to shorten the long list into an expression, such as "b013[5-9][0-9]", not the other way around...

  4. #4
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: How do I create QRegExp?

    "^b013[5-9]\d$" or "b013[5-9]\d"
    it depends on your filter purpose.
    Jerry

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

    Default Re: How do I create QRegExp?

    Quote Originally Posted by lni View Post
    that is, I need to shorten the long list into an expression, such as "b013[5-9][0-9]", not the other way around...
    Do you mean that you want to dynamically detect what's in the list and create as strict regular expression as possible based on the list contents?
    J-P Nurmi

  6. #6
    Join Date
    Dec 2006
    Posts
    426
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 18 Times in 17 Posts

    Default Re: How do I create QRegExp?

    Quote Originally Posted by jpn View Post
    Do you mean that you want to dynamically detect what's in the list and create as strict regular expression as possible based on the list contents?
    Yes, that is exactly what I am looking for...

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: How do I create QRegExp?

    That would be an AI question !! u can search for pattern matching algorithms,
    I dont think it will be easy to do in good time

Similar Threads

  1. Cannot create MySQL stored procedure / views from Qt
    By pshah.mumbai in forum Qt Programming
    Replies: 8
    Last Post: 8th October 2008, 16:22
  2. What is the best way to create a file management panel?
    By DIMEDROLL in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2008, 08:49
  3. Create tab?
    By songthanjp in forum Qt Tools
    Replies: 4
    Last Post: 12th March 2008, 16:11
  4. how to create resource fork & data fork
    By jyoti in forum General Discussion
    Replies: 4
    Last Post: 28th November 2006, 17:20
  5. How to create an Insert/Submit button for a form.
    By fnmblot in forum Qt Programming
    Replies: 5
    Last Post: 4th August 2006, 16:18

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.