For the common problem of matching text between delimiters (e.g. <
and >
), there's two common patterns:
*
or +
quantifier in the form START [^END]* END
, e.g. <[^>]*>
, or*?
or +?
quantifier in the form START .*? END
, e.g. <.*?>
.Is there a particular reason to favour one over the other?
Some advantages:
[^>]*
:
/s
flag.[^>]
the engine doesn't make choices - we give it only one way to match the pattern against the string)..*?
(?:(?!END).)*
. This is even worse if the END delimiter is another pattern.