I'm trying to create a regex that will take a string and replace certain characters
- Double or more spaces reduces to one space
- The following chars will be replaced by a word: "#" -> "number, "@" -> "at"
- Spaces will be replaced with "-", unless its at the end of the string
- Contains only a-z, A-Z, 0-9 and: !@#$%&/,
- Double or more "-" will reduce to one
"Hello, Wor--ld! 1$2@3- " -> "hello-wor-ld-1-dollars-2-at-3"
My code:
name = "Hello, World! 1$2@3- "
name = re.sub("[^a-zA-Z0-9]+","-",name.lower())
print(name)
But it results in "hello-world-1-2-3-"
#to ensure what it becomes ?!@#$%&should all correspond to some words. What is the full list? "*#->number,@->at,$->dollars", and the rest? Please fix your test case.