
Thanks for your help, linking was exactly the problem. As you can no doubt tell, I'm new not only to Boost but C++ in general. If you have the patience for one more newbie question ... I have the following code (in a FastCGI++ web application). The intention is to sanitise user input by allowing only alphanumeric characters, spaces, full stops and hyphens, simply replacing everything else with underscores: std::string input_name = environment.posts["name"].value; std::string filler = "_"; boost::regex re("[^a-zA-Z0-9\s.-]"); std::string output_name = boost::regex_replace(input_name, re, filler); Compilation fails with the following error: contact.cpp: In member function ‘virtual bool Contact::response()’: contact.cpp:48: error: unknown escape sequence '\s' The regex works fine with the \s removed (but of course replaces all spaces with underscores). These alternatives compile OK but don't work (program still replaces all spaces with underscores): [^a-zA-Z0-9\\s.-] [^a-zA-Z0-9[:space:].-] I know this is going to be something pretty basic, but how can I include whitespace - non-breaking, breaking, tabs, newlines, the lot - in the regex above as symbols to NOT be replaced? Thanks again Mike

Compilation fails with the following error:
contact.cpp: In member function ‘virtual bool Contact::response()’: contact.cpp:48: error: unknown escape sequence '\s'
The regex works fine with the \s removed (but of course replaces all spaces with underscores).
You need to use \\s as the escape is processed first by the compiler, and then by the regex engine, so a string literal of "\\" produces a single \ to be passed to the regex engine. John.
participants (2)
-
John Maddock
-
ninti@internode.on.net