Вопрос

I have string like this one:

    parser = new ASTParser(in, encoding);

After i tokenize those string I get:

    ASTParser(in, encoding);

Now, how can I perform regex to get only ASTParser?

I tried to do this using std::erase:

    str.erase(std::remove_if(str.begin(), str.end(), isLetter), str.end());

but the problem is that I get also parameters (ASTParserinencoding) and I don't want this.

Also, I would very appreciate solution with boost::regex.

Это было полезно?

Решение

No need for a regex -- all you have to do is scan until the first non-letter. Here's one way (note my std::string manipulation skills are a little rusty):

str.substr(0, std::distance(str.begin(), std::find_if_not(str.begin(), str.end(), isLetter));

Alternatively, you could use a regex like this:

([A-Za-z_][A-Za-z0-9_]*)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top