Regex Lookahead and Lookbehinds: followed by this or that
I'm trying to write a regular expression that checks ahead to make sure there is either a white space character OR an opening parentheses after the words I'm searching for. Also, I want it to look back and make sure it is preceded by either a non-Word ( \W ) or nothing at all (i.e. it is the beginning of the statement). So far I have, "(\\W?)(" + words.toString() + ")(\\s | \\()" However, this also matches the stuff at either ends - I want this pattern to match ONLY the word itself - not the stuff around it. I'm using Java flavor Regex. As you tagged your question yourself, you need