I have a field to store the Latest Comments on a Case. For email responses I would only like to store the current email response and not all of the historic replies.
Most of my email responses are split with
'On ' + 'DDD, MMM dd, YYYY at HH:MM XM' + 'Sender Name' + '<' + 'Sender Email' + '> wrote:'
i.e On Tue, Apr 5, 2022 at 10:10 AM Kimble Support [email protected] wrote:
I am using the following code to locate the string and return the text before...
String trimmed_before;
String trimRegExp = 'On ' + '(.+)' + '> wrote';
Matcher m = Pattern.compile(trimRegExp).matcher(input);
while(m.find()){
Integer startPosition = m.start();
System.debug('startPosition = ' + startPosition);
trimmed_before =input.mid(0,startPosition);
}
if(trimmed_before==null){
trimmed_before = input;
}
System.debug('trimmed_before = ' + trimmed_before);
However the "inner" portion of my Regex Pattern is too simplistic and returns anything starting with On and ending with wrote. How can I adjust the Pattern to match the format - 'On ' + 'DDD, MMM dd, YYYY....