import java.util.*;
import java.util.regex.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String regex = "(?U)\\b(?!(?:word1|word2)\\b)\\w+";
		Pattern p = Pattern.compile(regex);
	    Matcher m = p.matcher("Extract all words but word1 and word2.");
	    List<String> res = new ArrayList<>();
	    while(m.find()) {
	    	res.add(m.group());
	    }
	    System.out.println(res);
	}
}