I've been playing with this regex in Java for ages and can't get it to work:
(?:^| )(?:the|and|at|in|or|on|off|all|beside|under|over|next)(?: |$)
The following:
pattern.matcher("the cat in the hat").replaceAll(" ")
gives me cat the hat. Another example input is the cat in of the next hat which gives me cat of next hat.
Is there any way I can make this regex replacement work without having to break them out into multiple separate regexes for each word and try to replace a string repeatedly?
