How can I replace the first occurrence of a character in every word?

I would do a regex replacement on the following pattern:

@(@*)

And then just replace with the first capture group, which is all continous @ symbols, minus one.

This should capture every @ occurring at the start of each word, be that word at the beginning, middle, or end of the string.

inp = "hello @jon i am @@here or @@@there and want some@thing in '@here"
out = re.sub(r"@(@*)", '\\1', inp)
print(out)

This prints:

hello jon i am @here or @@there and want something in 'here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)