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.

NOTE: This will also might certain formatting, e.g. you might lose line breaks if they are saved as paragraph (p) or break (br) tags.

Revision #1
Created Wed, Jul 24, 2019 2:52 PM by PeopleSoft Wiki
Updated Wed, Jul 24, 2019 2:54 PM by PeopleSoft Wiki