Replacing numbers with a placeholder in a string inclding decimals and percentages using re in Python
def remove_numbers(text):
remove = re.sub(r"\W\d\S*", " [DD]", text,)
return remove
The function works fine on this sample string. sample = "I can give you 10% of 100,000 to you. The thing went up by 10% so it costs 12.25 euros now. But if a string starts with a number, the first numer does not get replaced by the placeholder.
I can give 50% of 100,000 to you in cash. it went up by 2.3% and its costly?