ABC HHHH fetID_3141 ProID_1045
上面是一个字符串,我需要提取fetID_3141
和ProID_1045
,主要需要数字3141
和1045
,如何使用c++进行规则匹配?
您可以使用std::regex
。
#include <iostream>
#include <regex>
int main()
{
std::regex r("[a-zA-Z]+_([0-9]+)");
std::smatch m;
std::string s = "ABC HHHH fetID_3141 ProID_1045";
while (std::regex_search(s, m, r))
{
std::cout << m[1] << std::endl;
s = m.suffix().str();
}
}