#include <iostream>
#include <string>
#include <regex>
int main() {
std::string text = "The quick brown fox jumps over the lazy dog.";
std::string expression = "fox"; // The expression to match before the word
// Match 'expression' followed by whitespace and a word
std::regex pattern(expression + R"(\s+(\w+))");
std::smatch match;
if (std::regex_search(text, match, pattern)) {
std::cout << "The first word after '" << expression << "' is: " << match[1] << std::endl;
} else {
std::cout << "No match found!" << std::endl;
}
}
/*
run:
The first word after 'fox' is: jumps
*/