re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work?

Veek M <[email protected]>
Newsgroups comp.lang.python
Organization A noiseless patient Spider
Message-ID <[email protected]>
look-ahead look-behind don't consume string so how does it advance through 
the string - could someone clearly explain how it works.

re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') 
'NA,1,NA,NA,two,3,NA,NA,NA'

re.sub(r'(?<![^,])(?![^,])', 'NA', ',1,,,two,3,,,')
'NA,1,NA,NA,two,3,NA,NA,NA'

My understanding is that there has to be a pattern that consumes the 
string eg: here [^,] consumes two 3 four and 5 but the look-ahead look-
behind eliminate 5

re.findall(r'(?<=,)[^,]+(?=,)', '1,two,3,four,5')
['two', '3', 'four']

If it's matching the empty string '' then why don't we get NA,NA1 etc 
for ,1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.