Regex
Jun 8, 2013 at 10:02am Jun 8, 2013 at 10:02am UTC
The following code is straight off the pages of C++ Primer and flat out doesn't work. The error it throws is just simply 'std::regex_error'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include<iostream>
using std::cout; using std::endl;
#include<string>
using std::string;
#include<regex>
using std::regex;
using std::smatch;
int main()
{
string pattern("[^c]ei" );
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*" ;
regex r(pattern);
smatch results;
string test_str = "recepit freind theif receive" ;
if (regex_search(test_str, results, r))
cout << results.str() << endl;
}
What could be the problem? I'm assuming it has to do with compiler/IDE. I'm using Code::Blocks that comes with the latest MingW. I think its' using gcc 4.7.1.
Jun 8, 2013 at 11:03am Jun 8, 2013 at 11:03am UTC
> What could be the problem?
libstdc++ has not implemented regular expressions.
C++11 support in libstdc++ is woefully incomplete.
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011
(grey and red all aound the place; regex is section 28)
It would have been better if spurious headers were not shipped with the library; at least some one would know immediately that
<regex>
just isn't there.
Use boost regex instead.
Jun 8, 2013 at 11:08am Jun 8, 2013 at 11:08am UTC
And to think an update is coming up next year. Thanks for the solution =).
Topic archived. No new replies allowed.