Problem with Qt and boost::regex

  • Thread starter magnus.moraberg
  • Start date
M

magnus.moraberg

The following code is not working as I expect it. The output for this
code is -

0
1
2
Found: Case_v73

If I replace:

boost::regex_match(directoryList.at(i).toStdString(), matches, pat)

with:

boost::regex_match(x, matches, pat)

I get the expected output:

0 Case_v73
1 Case
2 73
Found: Case_v73

How come?

toStdString() returns an object of type std::string.

Thanks,

Magnus


LocalCaseList::LocalCaseList(const QDir& caseDirectory)
: caseDirectory(caseDirectory)
{
QStringList directoryList = caseDirectory.entryList(QDir::Dirs,
QDir::Name);
for (int i = 0; i < directoryList.size(); i++)
{
boost::regex pat( "^(.+)_v([0-9]+)$" );
boost::smatch matches;

std::string x = directoryList.at(i).toStdString();

if (boost::regex_match(directoryList.at(i).toStdString(),
matches, pat))
{
for(int j = 0; j < matches.size(); j++)
std::cout << j <<matches[j]<< std::endl;

std::cout << "Found: " << directoryList.at(i).toStdString() <<
std::endl;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top