Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 29, 2017 15:42
Show Gist options
  • Save odeblic/083a1a87147a543d40b23e2a0e5e5042 to your computer and use it in GitHub Desktop.
Save odeblic/083a1a87147a543d40b23e2a0e5e5042 to your computer and use it in GitHub Desktop.
To be tested...
#include<string>
#include<set>
#include<iostream>
#include<sstream>
#include<regex>
using namespace std;
set<string> get_strings(istream& is, regex pat);
int main()
{
std::string str;
str += "http://loic-joly.developpez.com/articles/5Mythes/#L6\n";
str += "http://www.plandeparis.info/metro-paris/metro-paris.gif\n";
str += "https://mail.google.com/mail/u/0/#inbox\n";
stringstream ss(str);
regex pat("http.*m");
set<string> cont = get_strings(ss, pat);
for(std::set<string>::iterator it = cont.begin(); it != cont.end(); ++it)
{
std::cout << "str = " << *it << std::endl;
}
return 0;
}
set<string> get_strings(istream& is, regex pat)
{
set<string> res;
smatch m;
for(string s; getline(is, s); ) // lit une ligne
if (regex_search(s, m, pat))
res.insert(m[0]); // sauve le résultat dans set
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment