import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestRegex {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String input = "input", regex = "regex";
        Pattern p;
        Matcher m;        while (!input.equals("")) {
            try {
                System.out.print("Input: \n");
                input = in.readLine();
                System.out.print("Regular expression: \n");
                regex = in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }            p = Pattern.compile(regex);
            m = p.matcher(input);
            while (m.find()) {
                System.out.println("Match \"" + m.group() + "\" at positions " +
                        m.start() + "-" + (m.end() - 1));
            }
        }
    }
}命令行的,将就用吧...