1

こんにちは、メールからフッターを削除する方法を教えてください。メールの本文を保存し、免責事項やフッターなどの他のものを削除するだけです。

4

2 に答える 2

-1

正規表現を使用できます。

メールが次のように見えるとしましょう

String emailContents = 
    "AAA this is the email header BBB\n" +
    "This is the body\n" +
    "CCC this is the email footer DDD";

次のようなことができます。

Pattern pattern = Pattern.compile("AAA.*BBB(.*)CCC.*DDD");
Matcher matcher = pattern.matcher(emailContents);
if (!matcher.matches()) throw new Exception("Invalid email");
String emailBody = matcher.group(1);
System.out.println(emailBody); // prints 'This is the body'

.*任意の文字に複数回一致し、グループ()表すことに注意してください。完全な正規表現構文はこちら

于 2013-11-07T09:54:00.353 に答える