Skip to content

Instantly share code, notes, and snippets.

@abrjagad
Last active October 6, 2018 04:50
Show Gist options
  • Save abrjagad/1cd92cd3960a84efc1bf737c13a99d6d to your computer and use it in GitHub Desktop.
Save abrjagad/1cd92cd3960a84efc1bf737c13a99d6d to your computer and use it in GitHub Desktop.
Strip HTML tags and gives array with only valid elements
var a = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<a href="1.html">Hello World</a>
<a href="2.html">Hi Guys</a>
<a href="3.html">You are awesome</a>
<div class="example">See you</div>
</body>
</html>`
//regex from Csstricks.com
a.replace(/(<([^>]+)>)/ig,"").replace(/[\n]{1,}/gi,'').split(' ').filter(String);
// prints
// ["Document", "Hello", "World", "Hi", "Guys", "You", "are", "awesome", "See", "you"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment