What you want is called "groups" in regex. Groups are placed in parenthesis () and can be literal or symbolised regex syntax for types of stipulated characters.
java.util.Scanner and other associate Iterator interfaces and classes or java.lang.String and the main package java.util.regex for regular expressions contain tools for group capturing.
String abc = null; // weird but true for building regex into the expression on the fly in a re-callable method
String abc = new String("abc");
// hazard a guess such a data ***mining*** techniques would appear like this to capture groups whether present of not
Pattern p = "((\b)*"+abc+"(\b)*)* | ((\b)*xyz(\b)*)* | ((\b)*def(\b)*)*";