removeHtmlTags method

String removeHtmlTags({
  1. String replace = '',
})

Removes HTML tags from the string, optionally replacing them with a specified string.

This method uses a regular expression to identify HTML tags and remove them from the input string. If replace is provided, the HTML tags are replaced with the specified string instead of being removed.

Example:

var htmlString = '<p>Hello <b>World</b></p>';
var cleaned = htmlString.removeHtmlTags();
print(cleaned); // Outputs: Hello World

replace The string to replace HTML tags with. Defaults to an empty string.

Returns a string with HTML tags removed or replaced.

Implementation

String removeHtmlTags({String replace = ''}) {
  return replaceAll(RegExp(r'<[^>]*>'), replace);
}