# How to remove HTML tags from content?

**URL:** <https://forum.ionicframework.com/t/how-to-remove-html-tags-from-content/78011>\
**Category:** cordova\
**Created:** [February 1, 2017, 5:38am UTC](https://forum.ionicframework.com/t/how-to-remove-html-tags-from-content/78011 "2017-02-01T05:38:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mich356c](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mich356c/32/105794_2.png) [@mich356c](https://forum.ionicframework.com/u/mich356c)\
**Post date:** [February 1, 2017, 9:04am UTC](https://forum.ionicframework.com/t/how-to-remove-html-tags-from-content/78011/2 "2017-02-01T09:04:11Z")

</div>

Try this:

```
strip(html: string) {
	return html.replace(/<(?:.|\n)*?>/gm, '');
}

br2nl(html: string) {
	return html.replace(/<br( \/|\/|)>/gm, '\r\n');
}

```

Use it like so

```
strip(br2nl("<p>Night is a Theater,<br>Dream is a Movie,<br>God is the Director,<br>Nature is the Producer,<br>Your the Hero Enjoy the night with Sweet Dreams…</p>"));

```

`br2nl` would match the following

```
<br/>
<br />
<br>

```

Bear in mind that `strip` might also replace what looks like tags that the user has written, if not encoded. E.g. say I’m writing a post with the following text:

```
Here's a test text, if I did <this> then the outcome would be wrong

```

And the HTML equivalent would be

```
<p>Here's a test text, if I did <this> then the outcome would be wrong</p>

```

Then the strip would do this

```
Here's a test text, if I did then the outcome would be wrong

```

**Quick update:** Basically all you’d _need_ to encode would be `<` and `>`, so replace them with `&lt;` and `&gt;` respectively. So the HTML would like like this

```
<p>Here's a test text, if I did &lt;this&gt; then the outcome would be right*</p>

```

\* Right as in you _might_ need to decode them again before displaying them to the user

---

_[View the full topic](https://forum.ionicframework.com/t/how-to-remove-html-tags-from-content/78011)._
