You need to sign in to do that
Don't have an account?

Error 'Regex too complicated' in Apex
try{ // try start
if(email.plainTextBody == null || email.plainTextBody.Trim() == ''){//Creating the TextBody
system.debug('>> Inside plain text body with null');
pattern myPattern = pattern.compile('<.*?>');
//email.plainTextBody = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('<','<').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');
String newStr = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');
//modified the replace method since we are not able to replace '<'
// Need to uncomment if below method does not work for Regex exception
//String newStr = String.valueOf(myPattern.matcher(email.HtmlBody.stripHtmlTags()));
String finalStr = newStr.replace('<','<');
email.plainTextBody = finalStr;
system.debug('###>> New String value ##<<'+newStr);
}
}
this is my code: getting regex error, in the below mention line please help.
String newStr = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');
if(email.plainTextBody == null || email.plainTextBody.Trim() == ''){//Creating the TextBody
system.debug('>> Inside plain text body with null');
pattern myPattern = pattern.compile('<.*?>');
//email.plainTextBody = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('<','<').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');
String newStr = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');
//modified the replace method since we are not able to replace '<'
// Need to uncomment if below method does not work for Regex exception
//String newStr = String.valueOf(myPattern.matcher(email.HtmlBody.stripHtmlTags()));
String finalStr = newStr.replace('<','<');
email.plainTextBody = finalStr;
system.debug('###>> New String value ##<<'+newStr);
}
}
this is my code: getting regex error, in the below mention line please help.
String newStr = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('"','"').replaceAll('>','>').replaceAll(' ',' ').replaceAll('&','&')).replaceAll('');