0

I am trying to take a string in C++ and find the project name and path contained inside. The string has the format:

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL01", "OpenGL01\OpenGL01.vcxproj", "{65E58BFD-4339-44BA-BA9B-B2B8A5AC1FE1}"

And the regular expression is:

boost::regex expression("(Project\(\"\{.*\}\"\)) ?= ?(\".*\"), ?(\".*\"), ?(\"\{.*\}\")");

But this line generate a exception error:

Unhandled exception at 0x7512d36f in kmCompile2010.exe: Microsoft C++ exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> > at memory location 0x004ce13c..

This is the complete function:

BOOL CSlnFile::ReadProjectsSolution()
{
    CString sLine;
    boost::regex expression("(Project\(\"\{.*\}\"\)) ?= ?(\".*\"), ?(\".*\"), ?(\"\{.*\}\")");

    BOOL bCheck = FALSE;

    SeekToBegin();

    while(ReadString(sLine) && !bCheck) {   
        // CString to char*
        CT2A temp(sLine);           // uses LPCTSTR conversion operator for CString and CT2A constructor
        const char* pszA = temp;    // uses LPSTR conversion operator for CT2A
        std::string strA(pszA);     // uses std::string constructor

        boost::smatch what;

        if (regex_match(strA, what, expression, boost::match_extra)) {
            // TODO
        }
    }

    return bCheck;
}

I not found my mistake. Can you help me?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Joan Carles
  • 303
  • 5
  • 16
  • You need to double-escape everything but the quotes: `boost::regex expression("(Project\\(\"\\{.*\\}\"\\)) ?= ?(\".*\"), ?(\".*\"), ?(\"\\{.*\\}\")");` – ildjarn Apr 23 '12 at 21:20

1 Answers1

0

I didn't try the the following regex in boost::regex, it works in perl:

\{([^}]+)\}"[^"]*"([^"]+)", "([^"]+)", "\{([^}]+)

I tried it on the command line:

echo 'Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL01", "OpenGL01\OpenGL01.vcxproj", "{65E58BFD-4339-44BA-BA9B-B2B8A5AC1FE1}"' | perl -ne 'my ($a, $b, $c, $d) = /\{([^}]+)\}"[^"]*"([^"]+)", "([^"]+)", "\{([^}]+)/; print "$a, $b, $c, $d"'
neevek
  • 11,760
  • 8
  • 55
  • 73