0

I am trying to remove the first line in a string using regex.

As we know, the line return is OS dependent so I am using \r\n|\n|\r as regex.

The only issue is, i cannot get it to work..

int findMatchOffset(const std::string & iStr, const boost::regex & iExpression)
{
    boost::smatch aResults;
    if(boost::regex_match(iStr, aResults, iExpression))
    {
        return aResults.position();
    }
    return -1;
}

void removeFirstLine(std::string & ioMessageStr)
{
    boost::regex kNewLine("\r\n|\n|\r", boost::regex_constants::bk_vbar);
    int aIndex = findMatchOffset(ioMessageStr, kNewLine);

    ioMessageStr.erase(0, aIndex + 1);
}

Can you spot the error in the code above?

regex_match returns false, why?

Thanks for your help.

Orkun
  • 6,998
  • 8
  • 56
  • 103

0 Answers0