(?im)^\s*put\s((?!(after|into|before|\\)).)*$ the after|into|before , guessing the vertical bar means "or" but is not working. It only works for whatever the first word is and then still finds the next two.