0

I'm just starting out with boost and c++ and I'm struggling to understand the behaviour of boost's regular expression engine when it comes to matching whitespace. If I use the code:

boost::regex rx(" ");
cout << regex_search(" ", rx);

to match spaces, then everything works as expected and the regex_search returns true. However, if I try replacing the regular expression with "\s" to match all whitespace characters, I never get a match, and the following code always outputs false:

boost::regex rx("\\s");
cout << regex_search(" ", rx);

What am I missing here?

As requested, here's my complete test case:

#include <boost/regex.hpp>
#include <iostream>

using namespace std;

int main()
{
    boost::regex rx("\\s", boost::regex::icase);
    cout << regex_search(" ", rx);
}
ndawson
  • 253
  • 4
  • 9
  • You're missing the actual code. Write a short program that compiles, runs, and illustrates the problem. – Pete Becker Nov 28 '12 at 20:56
  • hmmm... I wonder if it's an issue with my build of boost then (using MinGW on Windows 7 32bit). At least you've confirmed that there's nothing wrong with my understanding of regular expressions and that the code should be working fine! – ndawson Nov 28 '12 at 21:28
  • What version of boost and what version of gcc? I suspect you are using old versions. – Jesse Good Nov 28 '12 at 21:55

1 Answers1

2

Got it -- I was originally using the prebuilt libraries from ascend4.org/Binary_installer_for_Boost_on_MinGW . After building Boost 1.52 the code works as expected. Trying to shortcut the boost build process ended up costing me a couple of hours of frustration... I've learnt my lesson now!

ndawson
  • 253
  • 4
  • 9