std::tr1::regex string failure

pkivolowitz
pkivolowitz used Ask the Experts™
on
I have not used std::tr1::regex before but have used regex elsewhere a lot.

My program is crashing on this line:
std::tr1::regex r("^\s*track\d\s*\{\{\s*curve\s+x.+\} \{\s*curve\w+x.+\}\}\s*$");

with a bad regular expression error.

I have checked the regular expression syntax elsewhere and it seems fine.

I see that tr1::regex implements multiple regex languages - do I need to specify one? Which do I specify? Is my string really wrong?

To me this string is supposed to specify
std::tr1::regex r("^\s*track\d\s*\{\{\s*curve\s+x.+\} \{\s*curve\w+x.+\}\}\s*$");
beginning of line
any white space
track
single digit
any white space
{{
any white space
curve
any white space
x
anything
} {
any white space
curve
any white space
x
anything
}}
any white space
end of line

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
cup

Commented:
It might help the other MVPs to know which implementation of std::tr1 are you using?  Microsoft regex syntax is slightly different from the original Unix/perl regex syntax.
I did not check the regular expression meaning; however, you definitely have to double the backslashes in C-string literals:

std::tr1::regex r("^\\s*track\\d\\s*\\{\\{\\s*curve\\s+x.+\\} \\{\\s*curve\\w+x.+\\}\\}\\s*$");

Author

Commented:
Thank you! That was it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial