regular expressions regex is (? =namefor example(? \ +)\ +(? =wordmatches duplicate words using capture called "wordassertions and flags |one problem that affects many of the regexes we have looked at so far is that they can match more or different text than we intended for examplethe regex aircraft|airplane|jet will match "waterjetand "jetskias well as "jetthis kind of problem can be solved by using assertions an assertion does not match any textbut instead says something about the text at the point where the assertion occurs one assertion is \ (word boundary)which asserts that the character that precedes it must be "word(\wand the character that follows it must be non"word(\ )or vice versa for examplealthough the regex jet can match twice in the text the jet and jetski are noisythat isthe jet and jetski are noisythe regex \bjet\ will match only oncethe jet and jetski are noisy in the context of the original regexwe could write it either as \baircraft\ |\bairplane\ |\bjet\ or more clearly as \ (?:aircraft|airplane|jet)\bthat isword boundarynoncapturing expressionword boundary many other assertions are supportedas shown in table we could use assertions to improve the clarity of key=value regexfor exampleby changing it to ^(\ +)=([^\ ]+and setting the re multiline flag to ensure that each key=value is taken from single line with no possibility of spanning lines-providing no part of the regex matches newlineso we can' usesay\ (the flags are shown in table their syntaxes are described at the end of this subsectionand examples are given in the next section and if we want to strip whitespace from the ends and use named capturesthe regex becomes^\ ]*(? \ +)\ ]*=\ ]*(? [^\ ]+)(?<!\ ]even though this regex is designed for fairly simple taskit looks quite complicated one way to make it more maintainable is to include comments in it this can be done by adding inline comments using the syntax (?#the comment)but in practice comments like this can easily make the regex even more difficult to read much nicer solution is to use the re verbose flag--this allows us to freely use whitespace and normal python comments in regexeswith the one constraint that if we need to match whitespace we must either use \ or character class such as here' the key=value regex with comments^\ ](? \ +\ ]*=\ ](? [^\ ]+(?<!\ ]start of line and optional leading whitespace the key text the equals with optional surrounding whitespace the value text negative lookbehind to avoid trailing whitespace regex flags