simple regex doesn't match

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

int main() {
	string str = ".method public native testIntFromCarson()I";
	regex pattern("method");
	smatch m;

	if(regex_search(str, m, pattern)) {
		cout << "match" << endl;
	} else {
		cout << "not match" << endl;
	}
}

Since the str contains "method" and the pattern is "method", why it doesn't match?

Thanks
Are you using the broken gcc implementation of std::regex?

If you are, I'd suggest using boost.
I'm using gcc of MinGW 4.7.2, seems broken... why buggy code like this got released?
They may expect you to *gasp* read the manual.

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
search the document for regex.

As for why the current implementation just quietly fails in some instances (instead of, say, throwing an exception that makes it clear the implementation isn't complete) - I couldn't say.
aha,
Thanks cire.
why the current implementation just quietly fails in some instances

Simply because the original author disappeared after committing a few early work-in-progress bits, and nobody else found time or desire to do it for the gcc project.

Here's the explanation in libstdc++'s maintainer's own words: http://stackoverflow.com/a/12665408/273767
Last edited on
Topic archived. No new replies allowed.