【发布时间】:2014-02-09 12:09:47
【问题描述】:
我在使用 c++ 正则表达式时遇到了问题。
我有一个像“f 123/123 1234/123/124 12”这样的字符串,我想得到“/”之前的所有数字。
这是我的正则表达式:
“\s(\d+)”。
我在http://rubular.com/ 上试过它,它有效。 这是我的代码:
std::regex rgx("\\s(\\d+)");
std::smatch match;
if (std::regex_search(line, match, rgx))
{
std::cout << "Match\n";
std::string *msg = new std::string();
std::cout << "match[0]:" << match[0] << "\n";
std::cout << "match[1]:" << match[1] << "\n";
std::cout << "match[2]:" << match[2] << "\n";
}
但我明白了:
匹配
匹配[0]:123
匹配[1]:123
匹配[2]:
我意识到match[0] 不像 Python 和 Ruby 中的“组”。
【问题讨论】: