On 8/5/2010 12:36 PM, MRAB wrote:
You don't need to reverse the string:
def thous_format(integer_string):
"""
add comma thousands separator(s) to an integer-valued string
"""
return re.sub(r"(?<=\d)(?=(?:\d\d\d)+$)", ",", integer_string)
Nice! My first encounter with a look-behind! It appears that a slight
simplification is possible:
return re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", integer_string)
There no harm in putting \d\d\d into a group, though the group is never
used.
-John
--
http://mail.python.org/mailman/listinfo/python-list