Can someone explain in clear language how the non-zero lookbehind assertion (?<=.) technically works in the example below? That is, can you actually walk through it? The code works fine and produces the correct result.
I read about (?<=\w) at http://www.regular-expressions.info/wordboundaries.html, but the explanation was not clear to someone trying to learn about lookbehind assertions. Thanks.
>>> text = 'sassy'
>>> for (regexp,subst) in [ (r'(?<=.)s', '5'),(r'^s', '$') ]:
... text = re.sub(regexp,subst,text)
...
>>> text
'$a55y'
Look-behind does just that: it verifies that whatever precedes the current character matches the look-behind expression.
In your case,
(?<=.)swill matchs, but only if what precedes it matches.(i.e. anything except CRLF).