This function is supposed to return the first instance of a vowel in a string, but it only works on lowercase. I thought regex_constants::icase
was supposed to handle uppercase letters as well. Also, feel free to suggest a better way to do this.
The following returns 0 (it now returns -1) for "HAPPY" and 3 for "GREaT":
#include <regex>
int firstVowel(std::string str)
{
std::smatch match;
std::regex pattern("[aeiou]", std::regex_constants::icase);
while (std::regex_search(str, match, pattern))
{
return match.position();
}
return -1;
}
I'm getting the returns through main:
std::cout << firstVowel("HAPPY") << "\n";
std::cout << firstVowel("GREaT") << "\n";