字符串 "我5岁了"
正则表达式 "(?!am )\d"
如果您前往http://regexr.com/并将正则表达式应用于该字符串,您将获得数字5。 我希望使用std :: regex获得此结果,但我不理解如何使用匹配结果,而且可能还需要更改正则表达式。
std::regex expression("(?!am )\\d");
std::smatch match;
std::string what("I am 5 years old.");
if (regex_search(what, match, expression))
{
//???
}
5
永远不会等于a
。(?!am )\d
与\d
相同。 - Wiktor Stribiżew"I am (\d)+ years old"
并使用捕获呢? - Mateen Ulhaq