Regular Expression .*? and .*
<p>What do these two regular expressions do?</p>

<pre class="lang-none prettyprint-override"><code>/&lt;(.*?)&gt;.*?&lt;\/\1&gt;/

/&lt;(.*?)&gt;.*&lt;\/\1&gt;/
</code></pre>

<p>What I've learned is <code>.*?</code> means as few characters as possible.</p>

<p>For example:</p>

<pre><code>  my $a = '"helllo"++"world"';

  print "a $1\n" if $a =~/(".*")/;            # "helllo"++"world"

  print "b $1\n" if $a =~/(".*?")/;           # "helllo"

  print "c $1\n" if $a =~/(.*)/;              # "helllo"++"world"

  print "d $1\n" if $a =~/(.*?)/;             # (nothing)
</code></pre>

<p>why does d show nothing, and b is <code>helllo</code> not <code>""</code>? </p>

<p>So, i couldn't find any good examples to show the difference between <code>1 and 2</code> like the <code>helllo world</code> example.</p>

<p>Can someone help by giving some examples to show the difference? </p>

<p>Thanks.</p>