#include#include int main() { std::string s = "John Smith (555) 555-1234"; std::regex rgx("([A-Z][a-z]+) ([A-Z][a-z]+) \\(([0-9]{3})\\) ([0-9]{3}-[0-9]{4})"); std::smatch match; std::regex_search(s, match, rgx); for (std::size_t i = 0; i < match.size(); ++i) { std::cout << "match[" << i << "]: " << match[i].str() << std::endl; } return 0; }
#includeThis code iterates through a string and prints out each word that contains only lowercase letters. The regular expression pattern `[a-z]+` matches one or more lowercase letters. `std::sregex_iterator` is used to iterate through the string and generate `sub_match` objects for each match. The `->` operator is used to access the `sub_match` object's `str()` method to print out each matched word. The `sub_match` type is part of the C++ Standard Library `#include int main() { std::string s = "The quick brown fox jumps over the lazy dog"; std::regex rgx("[a-z]+"); for (std::sregex_iterator itr(s.begin(), s.end(), rgx); itr != std::sregex_iterator(); ++itr) { std::cout << itr->str() << std::endl; } return 0; }