Regex pattern behaving differently in TCL compared with Perl & Python
<p>I am trying to extract a sub-string from a string using regular expressions. Below is the working code in <code>Python</code> (giving desired results)</p>

<p><strong>Python Solution</strong></p>

<pre><code>x = r'CAR_2_ABC_547_d'
&gt;&gt;&gt; spattern = re.compile("CAR_.*?_(.*)")
&gt;&gt;&gt; spattern.search(x).group(1)
'ABC_547_d'
&gt;&gt;&gt;
</code></pre>

<p><strong>Perl Solution</strong> </p>

<pre><code>$ echo "CAR_2_ABC_547_d" | perl -pe's/CAR_.*?_(.*)/$1/'
ABC_547_d
</code></pre>

<p><strong>TCL Solution</strong> </p>

<p>However, when I try to utilize this approach in <code>Tcl</code>, it is giving me different results. Can someone please comment on this behavior</p>

<pre><code>% regexp -inline "CAR_.*?_(.*)" "CAR_2_ABC_547_d"
CAR_2_ {}
</code></pre>

<p>Another approach, instead of capturing the text that follows the prefix, is to just remove the prefix:</p>

<pre><code>% set result [regsub {^CAR_.*?_} "CAR_2_ABC_547_d" {}]
ABC_547_d
</code></pre>

python perl tcl tclsh