Articles in this section

Remove rich text or HTML markup from RTF fields

When a rich text format (RTF) field in your source application maps to a plain text field in your destination application, the destination can receive unwanted HTML or rich text markup. You can use a Handlebars expression with a regular expression to strip that markup and keep only the plain text.

Sample data

<b>Testing <u>testing&nbsp;</u><font size="2">&nbsp;</font><font size="1">testing&nbsp;</font></b><a href="http://example.com" target="_blank">testing</a>

Remove the markup

This expression uses the regexReplace helper to remove HTML tags and &nbsp; entities from the field:

{{{regexReplace field.name "" "(&nbsp;|<([^>]+)>)" "ig"}}}

Replace field.name with the field you want to clean. The regular expression (&nbsp;|<([^>]+)>) matches either a &nbsp; entity or any HTML tag, and the empty replacement value ("") removes each match. The i flag makes the match case-insensitive, and the g flag applies it to every match in the field. The triple braces ({{{ }}}) keep integrator.io from re-escaping the output.

Notes and constraints

  • The pattern removes each &nbsp; entirely rather than converting it to a space, so text separated only by &nbsp; can run together.
  • The pattern handles HTML tags and &nbsp; only. If your data contains other HTML entities, such as &amp; or &lt;, add them to the regular expression so they're removed or replaced as well.