/ aaaaa # Find me aaaaa (?: # Followed by, but do not capture (?: # Group but do not capture (?! # Something which is not aaaaa . #and any char including newline ) )* # As many as possible ) /gs # Repeat the match, dots can include newlines