<<程式>>
#include <regex> #include <string> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { try{ regex re("\\d++"); string input("123 23 435 asd 000"); sregex_iterator ite(input.begin(), input.end(), re); sregex_iterator iteEnd; for(; ite != iteEnd; ++ite){ cout << "found: " << ite->str() << " at " << ite->position() << " length " << ite->length() << endl; } } catch(regex_error& e){ cout << "Error: " << e.what() << endl; } return 0; }
<<輸出>>
found: 123 at 0 length 3
found: 23 at 4 length 2
found: 435 at 7 length 3
found: 000 at 15 length 3