Вот решение для регулярных выражений:
import java.util.regex.*;
class Test {
public static void main(String[] args) {
String input = "Date: XXXXX\n"
+ "Reply-To: XXXXX\n"
+ "Sender: XXXXX\n"
+ "From: XXXX\n"
+ "Subject: Test\n"
+ "In-Reply-To: XXXX\n"
+ "Mime-Version: 1.0\n"
+ "Content-Type: multipart/alternative; " +
"boundary=\"=__Part416ABDAE.0__=\"";
Pattern p = Pattern.compile("(.*?):\\s+(.*)");
Matcher m = p.matcher(input);
while (m.find()) {
System.out.println("Key: " + m.group(1));
System.out.println("Val: " + m.group(2));
System.out.println();
}
}
}
Выход:
Key: Date
Val: XXXXX
Key: Reply-To
Val: XXXXX
Key: Sender
Val: XXXXX
Key: From
Val: XXXX
Key: Subject
Val: Test
Key: In-Reply-To
Val: XXXX
Key: Mime-Version
Val: 1.0
Key: Content-Type
Val: multipart/alternative; boundary="=__Part416ABDAE.0__="