Opened 11 years ago

Closed 10 years ago

#6213 closed Bugs (worksforme)

Escaping close parentheses doesn't work in boost::regex

Reported by: anonymous Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

Currently I am running Boost 1.47 on Scientific Linux 6 and cannot get the escaped close parentheses to match in a very simple expression. I can remove the escaped close parentheses and the regular expression will match, but with the escaped close parentheses, we never can get the if statement to work. I can put a small work around in our codebase, but I would expect this feature to work. Below is a example snippet of code:

void MyFuction(const std::string& val)
{
  boost::regex  expr1("(.*)\\((.*)\\)");
  boost::regex  expr2("(.*)\\((.*)");
  boost::cmatch matches;
  
  if(boost::regex_match(val.c_str(), matches, expr1)) {
    //never will get in here
  }

  if(boost::regex_match(val.c_str(), matches, expr2)) {
    //will get in here when we expect it to
  }

}

I appologize if there's something on my side that I'm missing, but I searched around and really can't find anything in our code base that would indicate its our code base and not boost::regex.

Change History (4)

comment:1 by Steven Watanabe, 11 years ago

It seems to work with MSVC 10 with the trunk:

#include <string>

#include <boost/regex.hpp>



void f(const std::string& val)

{

    boost::regex expr1("(.*)\\((.*)\\)");

    boost::cmatch matches;

    if(boost::regex_match(val.c_str(), matches, expr1))

    {

        std::cout << "matched" << std::endl;

    }

}



int main () {

    f("test(test)");

}

I don't see any obvious recent changes that would affect this. Do you have an example string that fails to match?

comment:2 by viboes, 11 years ago

Component: Noneregex
Owner: set to John Maddock

comment:3 by John Maddock, 11 years ago

As Steven says, we need to see the string that failed to match to tell you what's going on. My suspicion is that the string has content after the closing ")" in which case regex_match will fail (remember regex match only succeeds if the whole of the text was matched).

comment:4 by John Maddock, 10 years ago

Resolution: worksforme
Status: newclosed

Closed pending further information from the user.

Note: See TracTickets for help on using tickets.