samedi 1 avril 2017

How to get the href value in c++ using regex?

I want to fetch the value of href in c++, but my code is not giving the desired result

#include <fstream>
#include <iostream>
#include <string>
#include <regex>


int main()
{

   std::regex url("/.*(href=')(.*)('>)/");
  std::string url_test = "hjsh.ppt";
    std::ifstream file("in.txt");
    if (!file.is_open())
    {
        std::cerr << "Failed to open file!\n";
        return -1;
    }


    const std::string needle = "href";


    while (std::getline(file, url_test))
    {
        if (url_test.find(needle) != std::string::npos)
        {
          if(regex_match(url_test, url)){}
            std::cout << url_test << "\n";

        }
    }
}

The above code prints whole line as

<a href="11_custom_io.ppt">Ch11: Customizing I/O</a>

I want only 11_custom_io.ppt , name of the file. Please Help.

Aucun commentaire:

Enregistrer un commentaire