24 Apr
2006
24 Apr
'06
4:37 p.m.
If my code contains the following regexp,
const boost::tregex non_printables(__T("[^\0x21-\0x7E]+"));
Don't forget that your pattern is scanned first by the C++ compiler. In this case, this means that \0x21 is never seen by the RegExp engine; instead, it sees a NUL character (ASCII 0) followed by "x21". NUL is not valid in any pattern and thus an exception is thrown. Use double backslashes to get a backslash through to the engine.
Quite right, and just to add to that: it's very helpful if you add a try...catch handler in main so that unhandled exceptions don't crash the application. Or to put it another way, error handling is a "good thing" :-) John.