Skip to content

Instantly share code, notes, and snippets.

@ussjoin
Created August 18, 2009 19:11
Show Gist options
  • Save ussjoin/169892 to your computer and use it in GitHub Desktop.
Save ussjoin/169892 to your computer and use it in GitHub Desktop.
import java.util.regex.*;
public class Test
{
public static void main(String[] args)
{
String haystack = "<html><head><title>The Title</title></head><body>Some words are here</body></html>";
String stripHTMLPattern = "<[^>]*>";
Pattern pattern = Pattern.compile(stripHTMLPattern);
Matcher matcher = pattern.matcher(haystack);
String stripped = matcher.replaceAll(" ");
System.out.println(stripped);
}
}
/*
* Compare to the same in Perl:
* my $haystack = "<html><head><title>The Title</title></head><body>Some words are here</body></html>";
* $haystack =~ s/\<[^>]*\>/\ /g;
* print "$haystack\n";
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment