Last active
January 27, 2016 03:40
-
-
Save kyle-go/e36a6819c859079f2989 to your computer and use it in GitHub Desktop.
c++ regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdafx.h" | |
| #include <regex> | |
| using namespace std; | |
| int main() | |
| { | |
| string str = "xxxABC999yjdskABC444阿凡ABC0_达ABC77汉字eABC9"; | |
| const regex reg("ABC[0-9]+"); | |
| smatch results; | |
| std::string::const_iterator it = str.begin(); | |
| std::string::const_iterator end=str.end(); | |
| vector<string> v; | |
| while (regex_search(it, end, results, reg)) { | |
| v.push_back(results[0]); | |
| it=results[0].second; | |
| } | |
| for (auto it = v.begin(); it != v.end(); it++) { | |
| printf("%s\n", it->c_str()); | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment