regex error with valid regex string

I've tested the string and found it to be valid (as it should be) and it matches in perl, but in C++ it throws a regex_error with code 4. For the life of me I can't figure out why. I'm new to regex, and my googling has been fruitless.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <regex>
#include <string>
using namespace std;

int main() {
	try 	{
		regex rgx("(^[A-Za-z])");
		smatch match;
		string name = "Alex Evans";

		if(std::regex_search(name,match,rgx)) {
			cout << "match[1] = " << match[1] << endl;
		}
	} catch(std::regex_error e) {
		cout << e.code() << endl;
	}
	return 0;
}
Are you using the GNU compiler (release prior to [2013-10-03])?
GCC 4.8.1
Regex support is not available

Upgrade to GCC 4.8.2 (haven't tested that version myself, but I guess it would have regex support.)

Or use boost::regex instead.
Unfortunately that's not possible at the moment. Well crap. I guess I'll go at it again later.

I hate that it compiles perfectly fine as is, though.
4.8.2 doesn't have it yet, it's in the 4.9 trunk
The GNU C library has long had a <regex.h>, which is very useful.
Give it a try.
Topic archived. No new replies allowed.