Is the behavior of Python vs Perl regex for carat and dollar different? : <p>In Python:</p>

<p>Given a string <code>'ve</code>, I can catch the start of the string with carat:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; s = u"'ve"
&gt;&gt;&gt; re.match(u"^[\'][a-z]", s)
&lt;_sre.SRE_Match object at 0x1109ee030&gt;
</code></pre>

<p>So it matches even though the length substring after the single quote is > 1.</p>

<p>But for the dollar (matching end of string):</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; s = u"'ve"
&gt;&gt;&gt; re.match(u"[a-z]$", s)
&gt;&gt;&gt; 
</code></pre>

<p>In Perl, from <a href="https://github.com/alvations/mosesdecoder/blob/master/scripts/tokenizer/detokenizer.perl#L128" rel="nofollow noreferrer">here</a></p>

<p>It seems like the end of string can be matched with:</p>

<pre><code>$s =~ /[\p{IsAlnum}]$/
</code></pre>

<p>Is <code>$s =~ /[\p{IsAlnum}]$/</code> the same as <code>re.match(u"[a-z]$", s)</code> ?</p>

<p><strong>Why is the carat and dollar behavior different? And are they different for Python and Perl?</strong></p>
