This is a homework assignment. OP wrote “Example” when he should have written “Test”.
The point is to transform each element of the
string to an email address.
Hence, “Jowal Dawn” ⟶ “Jowal Dawn <firstname.lastname@example.org>”.
There is no need to validate
anything. You need to implement the function
, which breaks the string into individual names, transforms those names into email addresses, and builds a new string with those parts.
(IRL, it is only possible to validate an email address by getting a response from someone you emailed.)
Don’t try to do everything
with the regular expression. Only use it to get the pieces. C++ has a
which will allow you to handle each name in
one at a time. All you need is a loop:
std::string solve( std::string & J, std::string & K )
std::regex re( ... ); // this is where you need to think
auto first = std::regex_iterator( J.begin(), J.end(), re );
auto last = std::regex_iterator();
for (auto iter = first; iter != last; ++iter)
std::smatch match = *iter;
// Use the pieces of `match` to build your new piece of string:
auto first_name = ...;
auto last_name = ...;
if (!result.empty()) result += "; ";
result += first_name + " " + last_name
+ " <" + lowercase(first_name) + "." + lowercase(last_name)
+ "@" + lowercase(K) + ".com>";
Notice that you will need a little utility function (
) to convert a string to lowercase.
The tricky part is designing your regular expression. Remember: you can get sub-expressions
by using parentheses in the regular expression. The
variable can be treated like an array to access those sub-matches.
is the entire
is the first parenthesized sub-
... and so on
Also remember that you can tag something as optional with a question mark.
Finally, remember that the regular expression matches the input
string. It does not match (or create) the result string.