Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/regex.hpp>
- #include <string>
- #include <iostream>
- using namespace std;
- using namespace boost;
- int main(int argc, char *argv[]) {
- if (argc < 2)
- return -1;
- string url = argv[1];
- cout << "url: " << url << endl;
- /* first problem */
- regex rx("((https?)\\://)?([^\\:/]+)(:([0-9]+))?(/[^\\?#]*)?(\\?([^#]*))?(#(.*))?");
- smatch match;
- if (regex_match(url, match, rx)) {
- cout << "scheme: " << match[2] << endl;
- cout << "domain: " << match[3] << endl;
- if (!match[5].str().empty())
- cout << "port: " << match[5] << endl;
- if (!match[6].str().empty())
- cout << "path: " << match[6] << endl;
- if (!match[8].str().empty())
- cout << "query: " << match[8] << endl;
- if (!match[10].str().empty())
- cout << "id: " << match[10] << endl;
- } else {
- cout << "!regex_match()" << endl;
- }
- /* second problem */
- string toRemove = "http://";
- size_t found = 0;
- if ((found = url.find(toRemove)) != string::npos) {
- cout << "found: " << found << endl;
- url.erase(found, toRemove.size());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement