<img\ [^>]*src(?(? ["'](? [^\ >]+?(? =quote(? [^">]+[^>]* start of the tag any attributes that precede the src start of the src attribute opening quote image filename closing quote matching the opening quote ---or alternatively--unquoted image filename any attributes that follow the src end of the tag the indentation is just for clarity the noncapturing parentheses are used for alternation the first alternative matches quote (either single or double)then the image filename (which may contain any characters except for the quote that matched or >)and finallyanother quote which must be the same as the matching quote we also had to use minimal matching+?for the filenameto ensure that the match doesn' extend beyond the first matching closing quote this means that filename such as " ' herepngwill match correctly note also that to refer to the matching quote inside the character class we had to use numbered backreference\ instead of (? =quote)since only numbered backreferences work inside character classes the second alternative matches an unquoted filename-- string of characters that don' include quotesspacesor due to the alternationthe filename is captured in "qimage(capture number or in "uimage(capture number since (? =quotematches but doesn' capture)so we must check for both the final piece of regex syntax that python' regular expression engine offers is means of setting the flags usually the flags are set by passing them as additional parameters when calling the re compile(functionbut sometimes it is more convenient to set them as part of the regex itself the syntax is simply (?flagswhere flags is one or more of (the same as passing re ascii) (re ignorecase) (re multiline) (re dotall)and (re verboseif the flags are set this way they should be put at the start of the regexthey match nothingso their effect on the regex is only to set the flags the regular expression module ||the re module provides two ways of working with regexes one is to use the functions listed in table )where each function is given regex as its first argument each function converts the regex into an internal format-- the letters used for the flags are the same as the ones used by perl' regex enginewhich is why is used for re dotall and is used for re verbose regex flags