Shortened code in replace/delete sub-functions

I combined the criteria for deciding whether whole words should be
matched or not, and discarded the unnecessary code that executes when
whole words shouldn't be matched, since this should do the same thing as
the code that executes when whole words should be matched, shortening
the code substantially.