Posted By

mifly on 02/09/10


Tagged

javascript html regx


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

johnloy


remove html tag from html


 / Published in: JavaScript
 

  1. var htmlStr = '<a>clicke me</a><p><b>block1</b></p>1 2g';
  2. var s = htmlStr.replace(/<[^>]*>/ig,'');
  3. var s = s.replace(/[(\/>)<]/ig,'');
  4. alert(s);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kajalchristian on July 27, 2010

Regular Expressions: stripping HTML tags

var htstring = '

Hello World

'; var stripped = htstring.replace(/(]+)>)/ig,"");

with (document) { write ('Original string:' + htstring + ''); write ('Stripped string:' + stripped); }

Posted By: kajalchristian on July 27, 2010

Regular Expressions: stripping HTML tags var htstring = '

Hello World

'; var stripped = htstring.replace(/(<([^>]+)>)/ig,"");

with (document) { write ('Original string:' + htstring + ''); write ('Stripped string:' + stripped); }

Posted By: kajalchristian on July 27, 2010

sorry i wanted to post the whole code but all u need is just to write a SINGLE line var stripped = htstring.replace(/(]+)>)/ig,"");

and your string may contain any html code like

tag or anything

You need to login to post a comment.