function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bheemudu neelibheemudu neeli 

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('&quot;','"').replaceAll('&lt;','<').replaceAll('&gt;','>').replaceAll('&nbsp;',' ').replaceAll('&amp;','&')).replaceAll('');
                String newStr = myPattern.matcher(email.HtmlBody.replaceAll('<br/>', '\n').replaceAll('&quot;','"').replaceAll('&gt;','>').replaceAll('&nbsp;',' ').replaceAll('&amp;','&')).replaceAll('');
                //modified the replace method since we are not able to replace '&lt;'
               // 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('&lt;','<');
                            
               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('&quot;','"').replaceAll('&gt;','>').replaceAll('&nbsp;',' ').replaceAll('&amp;','&')).replaceAll('');