Skip to content

Instantly share code, notes, and snippets.

@nelsonjiao
Forked from atbradley/stripTags.groovy
Created June 26, 2017 06:11
Show Gist options
  • Save nelsonjiao/9ec5044b153bff7db5e7c1951f89f528 to your computer and use it in GitHub Desktop.
Save nelsonjiao/9ec5044b153bff7db5e7c1951f89f528 to your computer and use it in GitHub Desktop.
Very simplistically remove HTML tags from strings.
public static String stripTags(String input) {
return input.replaceAll("\\<.*?>","");
}
// In Groovy we can add a stripTags method to the String class:
String.metaClass.stripTags() {
delegate.replaceAll("<(.|\n)*?>", '')
}
String.prototype.stripTags = function() { return this.replace(/<.+?>/g, ''); };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment