mardi 26 juillet 2016

Can you create custom patterns using C++ regexes?

Say I create a regex to check for a valid name that looks like this:

regex name("([A-Z][a-z]*\\s)([A-Z]\\.\\s)?([A-Z][a-z]*)");

What if I wanted to do it this way:

customRegex name = "[A-Z][a-z]*", middleInitial = "[A-Z]\\.";

regex fullName("{name}\\s({middleInitial}\\s)?{name}");

Is there a way to assign variable names to custom patterns like this and then use them in regexes, using <regex> and C++11?

Aucun commentaire:

Enregistrer un commentaire