stripHtml method Null safety

String? stripHtml()

Strips all HTML code from String.

Example

String html = '<script>Hacky hacky.</script> <p>Here is some text. <span class="bold">This is bold. </span></p>';
String stripped = foo.stripHtml(); // returns 'Hacky hacky. Here is some text. This is bold.';

Implementation

String? stripHtml() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  // ignore: unnecessary_raw_strings
  var regex = RegExp(r'<[^>]*>');
  return this!.replaceAll(regex, '');
}