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
Trif Cristian 7Trif Cristian 7 

How can I remove HTML content attributes in Java/APEX?

I want to remove from my regex all content for my attributes. Below I have my regular expression and I want to happen is to, for example, I have this: style=" padding:0cm 0cm 0cm 0cm" this is an HTML attribute and I want to remove what's inside the "" which is the content. So from style="padding:0cm 0cm 0cm 0cm" I want to be only style=""; and also from
style="font-family:"Open Sans",sans serif;color:#444444" to be only style=""....Can I remove my attribute content with regexp?

regexpStart = '(?<=Name:<o:p></o:p></span></p>###LB###</td>###LB###<td 
   style="padding:0cm 0cm 0cm 0cm">###LB##';
regexpStart += '#<p class="MsoNormal" style="line-height:18.0pt;mso-line- 
       height-rule:exactly"><span style="fon';
regexpStart += 't-family:&quot;Open Sans&quot;,sans serif;color:#444444">)'; 
regexpEnd = '(?=<o:p>)';
regexp = regexpStart + '.*?' + regexpEnd;
Raj VakatiRaj Vakati
Refer this link 

https://stackoverflow.com/questions/48251198/regex-pattern-to-replace-html-in-a-given-text-string

https://regexr.com/

https://www.regextester.com/1946
Alain CabonAlain Cabon
Hi,
 
string regexpStart = '(?<=Name:<o:p></o:p></span></p>###LB###</td>###LB###<td  style="padding:0cm 0cm 0cm 0cm">###LB##';
regexpStart += '#<p class="MsoNormal" style = "line-height:18.0pt;mso-line-height-rule:exactly"><span style ="fon';
regexpStart += 't-family:&quot;Open Sans&quot;,sans serif;color:#444444">)'; 
string regexpEnd = '(?=<o:p>)';
string regexp = regexpStart + '.*?' + regexpEnd;
system.debug(regexp);
string regexp2 = regexp.replaceAll('style([^=]*?)=([^"]*?)\".+?\"','style=\"\"');
system.debug(regexp2);
string regexp3 = regexp.replaceAll('style[ ]*?=[ ]*?\".+?\"','style=\"\"');
system.debug(regexp3);