How it works...

A simple regular expression that can parse the input file shown earlier may look like this:

    ^(?!#)(\w+)\s*=\s*([\w\d]+[\w\d._,\-:]*)$

This regular expression is supposed to ignore all lines that start with a #; for those that do not start with #, match a name followed by the equal sign and then a value that can be composed of alphanumeric characters and several other characters (underscore, dot, comma, and so on). The exact meaning of this regular expression is explained as follows:

Part Description
^ Start of line
(?!#) A negative lookahead that makes sure that it is not possible to match the # character
(\w)+ A capturing group representing an identifier of at least a one word character
\s* Any white spaces

Get Modern C++: Efficient and Scalable Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.