// Replace the built-in textArea.selectWord() which may select non-word characters even if there is a word on the left of the caret. // Author: AhLeung Cheng https://www.google.com/+AhLeungCheng // GNU General Public License caret = textArea.getCaretPosition(); if (caret > 0 && textArea.getText(caret-1,1).matches("\\w")) textArea.goToPrevCharacter(false); // ref: How to check if a character is a non-word boundary http://stackoverflow.com/questions/2961570/how-to-check-if-a-character-is-a-non-word-boundary textArea.selectWord();