- #include <regex>
- #include <iostream>
- /* be aware of https://stackoverflow.com/questions/39645660/stdregex-to-match-begin-end-of-string */
- int main(int ac, char *av[]
- {
- std::string Input{"myurl://foo:80/bar"};
- std::regex Pattern{"^(.+?)://(((.+?)(:(.+?))?@)?((.+?)(?::([0-9]+)){0,1}))(/(.*?))?$",
- std::regex_constants::ECMAScript};
- std::smatch Matches;
- if (std::regex_search(Input, Matches,
- Pattern)) {
- std::cout << Matches.size()
- << " submatches found!";
- for (size_t i{0}; i < Matches.size(); ++i) {
- std::cout << "\n\nSubmatch " << i << ": "
- << Matches[i] << "\n Length: "
- << Matches[i].length()
- << "\n First Character: "
- << *Matches[i].first
- << "\n Position: "
- << Matches.position(i) << std::endl;
- }
- }
- return 0;
- }
std::regex URL parser
Posted by Anonymous on Tue 23rd Jan 2024 13:52
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.