I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this:
regex regex_a (".."); string rewrite_a = "($1/$2)";
regex regex_b (".."); string rewrite_b = "($1)";
regex regex_c (".."); string rewrite_c = "($2)";
if (regex_match(string, regex_a)) {
cout << regex_replace(string, regex_a, rewrite_a);
} else if (regex_match(string, regex_b)) {
cout << regex_replace(string, regex_b, rewrite_b);
} else if (regex_match(string, regex_c)) {
cout << regex_replace(string, regex_c, rewrite_c);
}
Is this the cleanest way to do this? Isn't there a way to make a regex array and iterate through that? It would make the code much more readable.