Why does this not work?
re.sub('\\b[a@](\\W|[a@])*[s5$](\\W|[s5$])*[s5$](\\W|[s5$])*($|\\W)', '*', '@ss')
I do not see why @ss is not replaced by *. Similarly, @55 is not replaced.
These are replaced: a55, a5s, as5, ass
Thank you!
If you're trying a sort of "profanity" check - I would take the logic out the regex.
look_alike = {'@': 'A', '$': 'S'}
test_string = ''.join(look_alike.get(c, c) for c in your_string.upper()) # also look at `string.translate`
Then if 'ASS' in test_string - or similar with word boundaries using an re.
re.sub(r'[a@][s5$]{2}', '*', '@ass')be much simpler and give the same result, or am I missing something?