我有通過文件查找日期的代碼,但它沒有返回,它發現匹配我的正則表達式。正則表達式,找不到匹配
CODE:
std::string s(line);
std::smatch m;
std::regex e("^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$");
std::cout << "Target sequence: " << s << std::endl;
std::cout << "Regular expression: ^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$" << std::endl;
std::cout << "The following matches and submatches were found:" << std::endl;
while (std::regex_search(s, m, e)) {
for (auto x : m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
OUTPUT:
Success
Target sequence: 12/28/2002 2 15 38 43 50
Regular expression: ^[0,1]?d{1}/(([0-2]?d{1})|([3][0,1]{1}))/(([1]{1}[9]{1}[9]{1
}d{1})|([2-9]{1}d{3}))$
The following matches and submatches were found:
Enter q to quit:
是我的正則表達式不正確或者是別的東西嗎?
不能解決的東西,但只是您正則表達式的簡化:??'^ [0,1] \ d \ /(([0-2] \ d)|(3 [0,1]) )\ /((199 \ d)|([2-9] \ d {3}))$' – nhahtdh 2014-10-17 02:13:44
@nhahtdh謝謝 – 2014-10-17 02:22:54