Basic Boost Regex question

Posted by shuttle87 on Stack Overflow See other posts from Stack Overflow or by shuttle87
Published on 2010-03-30T13:42:10Z Indexed on 2010/03/30 13:53 UTC
Read the original article Hit count: 615

Filed under:
|
|

I'm trying to write some c++ code that tests if a string is in a particular format. In this program there is a height followed by some decimal numbers: for example "height 123.45" or "height 12" would return true but "SomeOtherString 123.45" would return false.

My first attempt at this was to write the following:

string action;
cin >> action;
boost::regex EXPR( "^height \\d*(\\.\\d{1,2})?$/" ) ;//height format regex
bool height_format_matches = boost::regex_match( action, EXPR ) ;
if(height_format_matches==true){
  \\do some stuff
}

However height_format_matches never seemed to be true. Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost