((?!excludeword).)* ?! is a negative look-ahead. Putting negative look-ahead before the dot causes regex engine to first find any occurrence of the negative look-ahead string, and only then, if the negative look-ahead string is not present, should an arbitrary character (due to the dot) match. finding js/css comment /* ... */ '/\/\*((?!\*\/).)*\*\//s'