While writing a regex pattern for substituting all the continuos '1's and single '1's as 's'. I found this quite confusing ,usage of '+' (used for matching 1 or more ) gave expected result, but '*' gave strange result
>>> l='100' >>> import re >>> j=re.compile(r'(1)*') >>> m=j.sub('*',l) >>> m '*0*0*'
While usage of '+' gave expected result.
>>> l='100' >>> j=re.compile(r'1+') >>> m=j.sub('*',l) >>> m '*00'
how does '*' in regex gives this, while its behaviour is to match 0 or more.