Results 1 to 6 of 6

Thread: QRegExp wild card matching problems

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default QRegExp wild card matching problems

    Hi Guys

    I'm struggling to figure out how to match sets of characters using QRegExp in Wildcard pattern syntax.

    I've tried many things but nothing wants to work. I'm trying to match a set of files ending in .flw and .ngc and I've tried the following:

    Qt Code:
    1. QRegExp rx("*.flw *.ngc");
    2. QRegExp rx("[*.flw *.ngc]");
    3. QRegExp rx("[*.flw][*.ngc");
    4. QRegExp rx("[*.flw]+[*.ngc]");
    To copy to clipboard, switch view to plain text mode 

    I've read the documentation but does not understand what means exactly:

    [...] Sets of characters can be represented in square brackets, similar to full regexps. Within the character class, like outside, backslash has no special meaning.
    Any guidance will be appreciated.
    Thanks,
    Jaco

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QRegExp wild card matching problems

    Try this
    Qt Code:
    1. QRegExp rx("*.flw|*.ngc");
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

  3. #3
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp wild card matching problems

    I've not tested this in QT, but this is valid for POSIX Regexp:
    Qt Code:
    1. QRegExp rx(".*\.(flw|ngc)$");
    To copy to clipboard, switch view to plain text mode 


    HTH.
    Last edited by NullPointer; 2nd December 2011 at 14:43. Reason: Added QT code

  4. #4
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QRegExp wild card matching problems

    Hi Guys

    Thanks for the answers. Unfortunately it still does now work for me. I'm going to post a bit more of my code, maybe the problem is not in the expression itself...

    Qt Code:
    1. QDir dir("Some Dir Path");
    2. dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    3. QStringList entry_list = dir.entryList();
    4.  
    5. QString filter = "*.*";
    6. QRegExp reg_exp(filter,Qt::CaseInsensitive,QRegExp::Wildcard);
    7. QStringList filtered_list = entry_list.filter(reg_exp);
    To copy to clipboard, switch view to plain text mode 

    The above filter works fine, it gives me all the files in entry_list. However none of the other ones work. So far I've tried:

    Qt Code:
    1. filter = "*.flw|*.ngc";
    2. filter = ".*\.(flw|ngc)$";
    3. filter = "*.flw *.ngc";
    4. filter = "[*.flw *.ngc]";
    5. filter = "[*.flw][*.ngc]";
    6. filter = "[*.flw]+[*.ngc]";
    7. filter = "[*.flw]|[*.ngc]";
    To copy to clipboard, switch view to plain text mode 

    Any suggestions will still be appreciated,
    Thanks,
    Jaco

  5. #5
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QRegExp wild card matching problems

    I don't know how to use QRegExp with multiple wildcard masks, but the following code will do the same task:
    Qt Code:
    1. QDir dir("Some Dir Path");
    2. dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    3.  
    4. QStringList filters;
    5. filters << "*.flw" << "*.ngc";
    6. dir.setNameFilters(filters);
    7.  
    8. QStringList filtered_list = dir.entryList();
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

  6. The following user says thank you to Oleg for this useful post:

    JPNaude (5th December 2011)

  7. #6
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QRegExp wild card matching problems

    Thanks Oleg, that works.

Similar Threads

  1. sd card
    By dmartino in forum Newbie
    Replies: 6
    Last Post: 19th January 2011, 21:34
  2. QregExp: matching accented letters
    By bred in forum Qt Programming
    Replies: 0
    Last Post: 4th January 2011, 10:48
  3. QRegExp not matching the { character !!
    By gontham in forum Newbie
    Replies: 3
    Last Post: 4th June 2010, 00:20
  4. Qt and graphics card
    By leoalvesmachado in forum Newbie
    Replies: 2
    Last Post: 21st May 2010, 20:57
  5. my Function gone wild
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2007, 10:20

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.