I want to replace repeated instances of the \"*\" character within a string with a single instance of \"*\". For example if the string is \"*
\"*\"
\"*
You wrote:
pattern.replace("*"\*, "*")
You meant:
pattern.replace("\**", "*") # ^^^^
You really meant:
pattern_after_substitution= re.sub(r"\*+", "*", pattern)
which does what you wanted.