lundi 29 juin 2015

regex_search in c++11 only selecting biggest subtring that matches .Also type mismatch in regex_search

The regex_search here selects only the longest substring in this program as the output is the whole string data. Is that the default behaviour?

Additionally if i pass the string without declaring it as a string first like this

      regex_search("<html><body>some data</body></html",m,samepattern) 

It throws an error of type mismatch .

Additionally if i only use without the additional 2nd parameter

      regex_search("some string",pattern);

it works.

The whole code is shown below

 #include<string>
 #include<regex>
 #include<iostream>
 #include<iomanip>
 using namespace std;

 int main()
 {
    smatch m;
    string data{"<html><body>some data</body></html"};
    bool found = regex_search(data,m,regex("<.*>.*</.*>"));
    //If regex_seacrh("<html><body>some data</body></html",same as above)
    //it throws type mismatch error for this string in regex header
    cout<<(found?m.str():"not found");
    return 0;
 }

Aucun commentaire:

Enregistrer un commentaire