Last active
October 6, 2018 04:50
-
-
Save abrjagad/1cd92cd3960a84efc1bf737c13a99d6d to your computer and use it in GitHub Desktop.
Strip HTML tags and gives array with only valid elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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