What you can do is something similar to the following:
Pattern p = Pattern.compile("\\w"); // Replace "\\w" with your pattern
String str = "Some String To Match";
Matcher m = p.matcher(str);
List<String> matches = new ArrayList<String>();
while(m.find()){
matches.add(m.group());
}
After this, matches
will contain every substring that matched the Pattern.
In this case, it is just every letter, excluding spaces.
If you want to turn a List<String>
into a String[]
just use:
String[] matchArr = matches.toArray(new String[matches.size()]);