Re: A regular expression question

2016-09-28 Thread Ben Finney
Cpcp Cp writes: > Look this > > >>> import re > >>> text="asdfnbd]" > >>> m=re.sub("n*?","?",text) > >>> print m > ?a?s?d?f?n?b?d?]? > > I don't understand the 'non-greedy' pattern. Since ā€˜n*ā€™ matches zero or more ā€˜nā€™s, it matches zero adjacent to every actual character. It's non-greedy because

A regular expression question

2016-09-28 Thread Cpcp Cp
Look this >>> import re >>> text="asdfnbd]" >>> m=re.sub("n*?","?",text) >>> print m ?a?s?d?f?n?b?d?]? I don't understand the 'non-greedy' pattern. I think the repl argument should replaces every char in text and outputs "". -- https://mail.python.org/mailman/listinfo/python-list