To underline strings for viewers like less.
underlined = normal.replace('', '_\b')
This also can be done with re.sub(), but I think it is natural to use string methods to handle non-RE strings. This cannot be done with '_\b'.join(), since it doesn't prepend '_\b'. - Inyeol Lee On Fri, Aug 09, 2002 at 10:13:12AM -0400, Guido van Rossum wrote:
Since '' in 'abc' now returns True, How about changing 'abc'.replace('') to generate '_a_b_c_', too? It is consistent with re.sub()/subn() and the cost for change is similar to '' in 'abc' case.
Do you have a use case? Or are you just striving for consistency? It would be more consistent but I'm not sure what the point is. I can think of situations where '' in 'abc' would be needed, but not so for 'abc'.replace('', '_').
--Guido van Rossum (home page: http://www.python.org/~guido/)