// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.util.regex.*;

public class RegexFun {
    public static String load(String fnm) throws Exception {
        StringBuffer sb = new StringBuffer("");
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fnm)));
        String line;
        while((line = in.readLine()) != null) {
            sb.append(line);
            sb.append('\n');
        }
        return sb.toString();
    }
    public static void main(String[] args) throws Exception {
        String data = load("C:\\email.txt");
        Pattern pattern = Pattern.compile("(?:question2:)(.*)(?:subject:)",Pattern.DOTALL);
        Matcher matcher = pattern.matcher(data);
        if(matcher.find()){
            System.out.println(data);
            System.out.println("-----------------------");
            System.out.println(matcher.group(1));
        }
    }
}
