Page 1 of 1

how to remove html tags in javascript

Posted: Tue Feb 08, 2005 1:44 am
by renu
Hi

Can anyone tell how to remove html tags from a string in javascript.

Thanks.

Posted: Tue Feb 08, 2005 1:56 am
by feyd
viewtopic.php?t=25494

the regex used later in the thread (sorry about the formatting) can be used to correctly remove all tags.

Posted: Tue Feb 08, 2005 2:06 am
by renu
hey but this is php code.i want to to use that in javascript.
Actually i have a string in javascript having html tags.i want to remove them before form submitting.

Posted: Tue Feb 08, 2005 2:14 am
by feyd
the regular expression in that thread can be transferred into javascript fairly easily.

Posted: Tue Feb 08, 2005 2:37 am
by renu
can u tell how to use that.

Posted: Tue Feb 08, 2005 2:49 am
by Chris Corbyn

Code: Select all

var matches = Somestring.match(/regexp(In)Here/)
Parentheses around the parts of the expression you wish to extract

Posted: Tue Feb 08, 2005 3:25 am
by Chris Corbyn
or even (after reading that thread) you need to do a search and replace as follows....

Code: Select all

var newstring = oldString.replace(/yourRegexp/, 'YourReplacement')
Just copy the regExp and replacement from the other thread and it'll work ;-)

EDIT: Here..

Code: Select all

var newString = taggedString.replace(/#<.*?(\s+&#1111;\w\W]+?(\s*=\s*(&#1111;''"]?).*?\\3))*?>#s/, '')