I should probably just go home and get some sleep, but for the life of me I can't figure out why this regular expression isn't working.

Basically, what I want to do is take a list of strings and search through it looking for any string where any word in the string starts with the filter text. I thought I was pretty sure I have the regex correct, but no matter what I do I can't get it to work properly.


Here's my little filter function:

Qt Code:
  1. void MyDialog::filter(QString filterText)
  2. {
  3. // clear out the gui list
  4. ui.stringList->clear(); // a combo box on my form holding a list of strings
  5. // set up the regular expression
  6. QRegExp regexp(QString("^.*\\b%1.*$").arg(filterText),Qt::CaseInsensitive,QRegExp::Wildcard);
  7. // strings is just a QStringList defined elsewhere
  8. ui.stringList->addItems(strings.filter(regexp));
  9. }
To copy to clipboard, switch view to plain text mode 


Now, if I make the QRegExp look like:
Qt Code:
  1. QRegExp regexp(QString("%1").arg(filterText),Qt::CaseInsensitive,QRegExp::Wildcard);
To copy to clipboard, switch view to plain text mode 
It works just like I expect, filling the gui box with a list with lines from the full list where the filter text appears anywhere in any word from that string.

Admittedly, my knowledge on regular expressions is a bit rusty, but and maybe I'm just not forming the regular expression correctly, but I've been searching google for a while trying to remember this stuff and if I have something wrong I just can't see it.

I mean, even doing something simple like QString("^%1").arg(filterText) doesn't work. So I'm at a bit of a loss.