I figure out how to remove special non alphanumeric character in python using the following function:
p_nonalphanum = re.compile('\W+')
def removeNonAlphaNum(string):
m = p_nonalphanum.match(string)
if m:
string = string[m.end():]
return string
I would like to keep some specials characters though such as ½, ¾ which i consider as number. How should i edit my regex?
e.g: from “• ½ cup flour” to “½ cup flour”
1 Answer