Regex: can't understand the endpos
<p>Could you help me understand why <code>print(truth(prog.match(text, 0, 6)))</code> equals true?</p>

<pre><code>import re
from operator import truth

prog = re.compile(r'&lt;HTML&gt;$')
text = "&lt;HTML&gt;            "
print("Last symbol: {}".format(len('&lt;HTML&gt;')-1))
print(truth(prog.match(text, 0, 6)))
print(truth(prog.match(text)))
</code></pre>

<p>If you use the <code>match(text, startpos, endpos)</code> method of a compiled regex, it will act as if you've passed <code>match(text[startpos:endpos])</code> (well, <a href="https://docs.python.org/3/library/re.html#re.regex.search" rel="nofollow">not exactly</a>, but for the purposes of <code>$</code>, it is). This means that it'll think <code>&lt;HTML&gt;</code> is at the end of the input (which is what <code>$</code> matches).</p>

<p>However, when this is not the case the extra whitespace at the end of <code>text</code> will prevent <code>$</code> from matching, so no match is found.</p>

python python-3.x