Matching text between delimiters: greedy or lazy regular expression?
For the common problem of matching text between delimiters (e.g. < and > ), there's two common patterns: using the greedy * or + quantifier in the form START [^END]* END , e.g. <[^>]*> , or using the lazy *? or +? quantifier in the form START .*? END , e.g. <.*?> . Is there a particular reason to favour one over the other? Some advantages: [^>]* : More expressive. Captures newlines regardless of /s flag. Considered quicker, because the engine doesn't have to backtracks to find a successful match (with [^>] the engine doesn't make choices - we give it only one way to match the pattern against