In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Chapter 23 // Exercise 14
Write a program that, like the one in section 23.8.7, can be used to experiment with pattern matching by typing in a pattern. However, have it read a file into memory (representing a line break with the new line character, '\n'), so that you can experiment with patterns spanning line breaks. Test it and document a dozen test patterns.
So I was confused with this one. I'm not sure if he meant, "create a new file with newlines replaced by \n" or "have a file with newlines in it". In the first case, the newline will need to be put as '\\n' in the regex pattern otherwise it will just match to the characters \ n, so the slash needs escaping. But in the second you can just have it as \n and it will continue searching the next line for the pattern.
With this in mind I decided to do both. Interestingly I discovered that if you type out a regex pattern at compile time, it will add the escape to the slash. Whereas if you type it in the console at runtime, it won't.
No comments:
Post a Comment