Boost logo

Boost Users :

Subject: Re: [Boost-users] regex
From: ninti_at_[hidden]
Date: 2010-01-03 06:27:10


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
 
 
 


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net