Remove HTML Tags with Regex

The following is a rudimentary example of how you can remove HTML tags via PeopleCode using Regex (and the JavaObject):

function RemoveHTMLTags(&sInputHTML as String) Returns String
 
   Local JavaObject &jRemoveHTMLRegex = CreateJavaObject("java.lang.String", "<[^>]*>");
   Local JavaObject &jInputHTML = CreateJavaObject("java.lang.String", &sInputHTML);
   Local string &sPlainText = &jInputHTML.replaceAll(&jRemoveHTMLRegex, "");
 
   Return &sPlainText;
 
end-function;

Place this function (or turn it into an App class method) and use it as required. Useful for cases where the PeopleSoft rich-text editor has saved HTML in a DESCRLONG type field in the database.

This will also might certain formatting, e.g. you might lose line breaks if they are saved as <p></p> or <br/> tags.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License