vendredi 18 janvier 2019

Regex inside a function [duplicate]

This question already has an answer here:

I am trying to call a regex inside of a function, returns the matches and display them.


Using the following string to match :

dddd [k  ]MM ss 

regex101 tells me I should match like :

enter image description here


The result in my program is :

{�W
}
{}
{�W
}
{}



std::smatch firstTreatingRegex(std::string format) {
        std::regex regex("(\\[.*\\])|((?:[a-z]+|[A-Z]+)*\\ +)|([a-z]+|[A-Z]+)");
        std::smatch matches;

        std::regex_search(format, matches, regex);

        return matches;
}

std::smatch macthes = firstTreatingRegex(format);

for (unsigned i = 0; i < macthes.size(); ++i) {
        std::cout << "{" << macthes[i].str() << "}" << std::endl;
}

Aucun commentaire:

Enregistrer un commentaire