possible to match any and all text in non-greedy fashionuse the dotstarand question mark *?like with bracesthe question mark tells python to match in non-greedy way enter the following into the interactive shell to see the difference between the greedy and non-greedy versionsnongreedyregex re compile( ''mo nongreedyregex search(for dinner >'mo group('greedyregex re compile( ''mo greedyregex search(for dinner >'mo group(for dinner >both regexes roughly translate to "match an opening angle bracketfollowed by anythingfollowed by closing angle bracket but the string for dinner >has two possible matches for the closing angle bracket in the non-greedy version of the regexpython matches the shortest possible string'in the greedy versionpython matches the longest possible stringfor dinner >matching newlines with the dot character the dot-star will match everything except newline by passing re dotall as the second argument to re compile()you can make the dot character match all charactersincluding the newline character enter the following into the interactive shellnonewlineregex re compile(*'nonewlineregex search('serve the public trust \nprotect the innocent \nuphold the law 'group('serve the public trust newlineregex re compile(*'re dotallnewlineregex search('serve the public trust \nprotect the innocent \nuphold the law 'group('serve the public trust \nprotect the innocent \nuphold the law the regex nonewlineregexwhich did not have re dotall passed to the re compile(call that created itwill match everything only up to the first newline characterwhereas newlineregexwhich did have re dotall passed to re compile()matches everything this is why the newlineregex search(call matches the full stringincluding its newline characters