Remove everything after @ til next space until no more matches are found?

You may use this re.sub:

@\w+\s*

Code:

>>> s = "Hello @StackOverflow! How are you today? I'd like to !sh @StackExchange"
>>> print ( re.sub(r'@\w+\s*', '', s) )
Hello ! How are you today? I'd like to !sh

RegEx Details:

  • @: Match literal @:
  • \w+\s*: Match 1+ word characters followed by 0 or more whitespaces

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top