regular expressions process called compiling--and then does its work this is very convenient for one-off usesbut if we need to use the same regex repeatedly we can avoid the cost of compiling it at each use by compiling it once using the re compile(function we can then call methods on the compiled regex object as many times as we like the compiled regex methods are listed in table match re search( "#[\da-fa- ]{ }\ "textthis code snippet shows the use of an re module function the regex matches html-style colors (such as # abif match is found the re search(function returns match objectotherwiseit returns none the methods provided by match objects are listed in table if we were going to use this regex repeatedlywe could compile it once and then use the compiled regex whenever we needed itcolor_re re compile( "#[\da-fa- ]{ }\ "match color_re search(textas we noted earlierwe use raw strings to avoid having to escape backslashes another way of writing this regex would be to use the character class [\da-fand pass the re ignorecase flag as the last argument to the re compile(callor to use the regex (? )#[\da- ]{ }\ which starts with the ignore case flag if more than one flag is required they can be combined using the or operator (|)for examplere multiline|re dotallor (?msif embedded in the regex itself we will round off this section by reviewing some examplesstarting with some of the regexes shown in earlier sectionsso as to illustrate the most commonly used functionality that the re module provides let' start with regex to spot duplicate wordsdouble_word_re re compile( "\ (? \ +)\ +(? =word)(?!\ )"re ignorecasefor match in double_word_re finditer(text)print("{ is duplicatedformat(match group("word"))the regex is slightly more sophisticated than the version we made earlier it starts at word boundary (to ensure that each match starts at the beginning of word)then greedily matches one or more "wordcharactersthen one or more whitespace charactersthen the same word again--but only if the second occurrence of the word is not followed by word character if the input text was "win in vain"without the first assertion there would be one match and one capturewin in vain there aren' two matches because while (?pmatches and capturesthe \sand (? =wordparts only match the use of the word boundary assertion ensures that the first word matched is whole wordso we end up with no match or capture since there is no du