I am trying to remove the domain from a URL. The following is an example script.
#include & lt; Iostream & gt; #include & lt; String & gt; #include & lt; Boost / regex.hpp & gt; Int main () {std :: string url = "http://mydomain.com/randompage.php"; Boost :: regex exp ("^ https ?: // ([^ /] *?) /"); Std :: cout & lt; & Lt; Regex_search (url, exp); }
How do I print the matched value?
You need to use the surge of Regex_search that takes a match_results object in your case:
#include & lt; Iostream & gt; #include & lt; String & gt; #include & lt; Boost / regex.hpp & gt; Int main () {std :: string url = "http://mydomain.com/randompage.php"; Boost :: regex exp ("^ https ?: // ([^ /] *?) /"); Promotion: Smack Match; If (boost :: regex_search (url, match, exp)) {std :: cout & lt; & Lt; Std :: string (match [1]. First, match [1] .second); }}
Edit: right start, end ==> first, second
Comments
Post a Comment