Pages

Thursday, 7 April 2022

Chapter 23 // Exercise 3 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 3

Modify the email example from section 23.4 to use regular expressions to find the subject and sender.


So for this I used the site Regex101 to help craft the regex I needed:

This site is great as it gives explanations of what each part of the regex is doing and you can step through matches in the debugger.

For the subject, I assumed that we are finding it only in English and based off the email examples in the section. I got a bit annoyed as apparently std::regex doesn't support the very handy lookbehind feature. So I ended up just searching for "Subject:" then creating a string with everything in the message line after those 9 characters.

I then did the same for the sender.


No comments:

Post a Comment