When writing a regex pattern to replace all the continuums '1 and singles' 1 as 's'. I found this rather confusing, using "+" (used to match 1 or more) gave the expected result, but "*" gave a weird result
>>> l='100'
>>> import re
>>> j=re.compile(r'(1)*')
>>> m=j.sub('*',l)
>>> m
'*0*0*'
While using '+' gave the expected result.
>>> l='100'
>>> j=re.compile(r'1+')
>>> m=j.sub('*',l)
>>> m
'*00'
as '*' does in regex, and its behavior must match 0 or more.
source
share