By default .*
is greedy which means that it matches as much as possible. So with .*
the replacement would change:
This <b>is</b> an <i>example</i>.
^-------------------------^
to
This .
If you use a question mark after a quantifier it makes it non-greedy, so that it matches as little as possible. With .*?
the replacement works as follows:
This <b>is</b> an <i>example</i>.
^-^ ^--^ ^-^ ^--^
Becomes:
This is an example.
This is different from the more common use of ?
as a quantifier where it means 'match zero or one'.
Either way if your text is HTML you should use a HTML parser instead of regular expressions.