foostring <- c("First test *** no asterisks at the end", "Second test *** asterisks in the middle *** something different", "Third test *** more than one asterisk *** something different *** second asterisk ***", "Fourth test *** asterisks followed by a special character ***_something different") gsub("\\*{3}.*?(?:\\*{3}|$)", "", foostring)