The Matcher class in the java.util.regex package looks for a regular expression in text.

The Java application written below demonstrates the use of the find() and group() methods of the Matcher class.

 import java.util.regex.*;

public class ShowWords {
    
    public static void main(String[] arguments) {
        Pattern pattern = Pattern.compile("\\S+");
        Matcher matcher = pattern.matcher(arguments[0]);
        while (matcher.find())
            System.out.println("[" + matcher.group() + "]");
    }
}