Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用Boost.regex获得正则表达式匹配的值?_C++_Regex_Boost Regex - Fatal编程技术网

C++ 如何使用Boost.regex获得正则表达式匹配的值?

C++ 如何使用Boost.regex获得正则表达式匹配的值?,c++,regex,boost-regex,C++,Regex,Boost Regex,我正在尝试从URL提取域。下面是一个示例脚本 #include <iostream> #include <string> #include <boost/regex.hpp> int main () { std::string url = "http://mydomain.com/randompage.php"; boost::regex exp("^https?://([^/]*?)/"); std::cout << regex_

我正在尝试从URL提取域。下面是一个示例脚本

#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main () {

  std::string url = "http://mydomain.com/randompage.php";
  boost::regex exp("^https?://([^/]*?)/");
  std::cout << regex_search(url,exp);

}
#包括
#包括
#包括
int main(){
std::字符串url=”http://mydomain.com/randompage.php";
boost::regex exp(“^https?:/([^/]*?)/”;

std::cout您需要使用带有匹配结果对象的正则表达式搜索重载。在您的情况下:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main () {    
  std::string url = "http://mydomain.com/randompage.php";
  boost::regex exp("^https?://([^/]*?)/");
  boost::smatch match;
  if (boost::regex_search(url, match, exp))
  {
    std::cout << std::string(match[1].first, match[1].second);
  }    
}
#包括
#包括
#包括
int main(){
std::字符串url=”http://mydomain.com/randompage.php";
boost::regex exp(“^https?:/([^/]*?)/”;
小比赛;
if(boost::regex_搜索(url、match、exp))
{

std::cout first,second

我编译此文件时出错。main.cpp:在函数'int main()':main.cpp:11:error:'const struct boost::sub_match'没有名为'begin'main的成员。cpp:11:error:'const struct boost::sub_match'没有名为'end'的成员我的错误。我将修复它。它应该是第一个和第二个,而不是begin()和end()。