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 -- https://mail.python.org/mailman3//lists/python-list.python.org
