[Solved] How to Delete Strings that Start with Certain Characters in Ruby


Check if there’s a whitespace (\s) before or if it’s the start of the string (^).

(?:\s|^)@.*

Live Demo

If you only want to match word characters, then instead of using . you could use \w. Also note that * would still match just "@", so you might want to use + instead to match at least one character.

(?:\s|^)@\w+

Live Demo

3

solved How to Delete Strings that Start with Certain Characters in Ruby