Your problem is an interesting one,but your solution is not a great use of regular expressions, since there's the better option of using the 'word boundary' anchor \b. The boundary anchor matches a transition from a word, to a non-word, or vice versa.