I want to replace repeated instances of the \"*\" character within a string with a single instance of \"*\". For example if the string is \"*
\"*\"
\"*
Well regular expressions wise I would do exactly as JoshD has suggested. But one improvement here.
Use -
regex = re.compile('\*+') result = re.sub(regex, "*", string)
This would essentially cache your regex. So subsequent usage of this in a loop would make your regex operations fast.