By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Tag Replace

P: n/a
Hi,

How to replace a tag by space.
Example:
var str="<b>abcd</b>";

i need a str with "abcd";
replace <band </bby ""
Feb 4 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Feb 4, 1:03 pm, nithicor...@gmail.com wrote:
Hi,

How to replace a tag by space.
Example:

var str="<b>abcd</b>";

i need a str with "abcd";
replace <band </bby ""
See RegExp (regular expressions) tutorial on the net
Feb 4 '08 #2

P: n/a
On Feb 4, 6:12 pm, GArlington <garling...@tiscali.co.ukwrote:
On Feb 4, 1:03 pm, nithicor...@gmail.com wrote:
Hi,
How to replace a tag by space.
Example:
var str="<b>abcd</b>";
i need a str with "abcd";
replace <band </bby ""

See RegExp (regular expressions) tutorial on the net
This will replace all html tags from the input string i.e str
alert(str.replace(/<([a-z]*)>(.*)<\/\1>/i, "$2"));

1 2 3
1. Tag match
2. The string which need to retain.
3. End tag match (back references)

Thanks
Feb 4 '08 #3

P: n/a
"Amrit Ranjan" <am*****@gmail.comwrote in message
news:b2**********************************@i72g2000 hsd.googlegroups.com...
On Feb 4, 6:12 pm, GArlington <garling...@tiscali.co.ukwrote:
On Feb 4, 1:03 pm, nithicor...@gmail.com wrote:
Hi,
How to replace a tag by space.
Example:
var str="<b>abcd</b>";
i need a str with "abcd";
replace <band </bby ""
See RegExp (regular expressions) tutorial on the net

This will replace all html tags from the input string i.e str
alert(str.replace(/<([a-z]*)>(.*)<\/\1>/i, "$2"));

1 2 3
1. Tag match
2. The string which need to retain.
3. End tag match (back references)

Thanks
"all html tags"?

That converted:
<html><body><b>Hello World!</b></body></html>
to
<body><b>Hello World!</b></body>

Shoud it convert it to just:
Hello World
Feb 4 '08 #4

P: n/a
On Feb 4, 2:23 pm, "McKirahan" <N...@McKirahan.comwrote:
"Amrit Ranjan" <amri...@gmail.comwrote in message

news:b2**********************************@i72g2000 hsd.googlegroups.com...
On Feb 4, 6:12 pm, GArlington <garling...@tiscali.co.ukwrote:
On Feb 4, 1:03 pm, nithicor...@gmail.com wrote:
Hi,
How to replace a tag by space.
Example:
var str="<b>abcd</b>";
i need a str with "abcd";
replace <band </bby ""
See RegExp (regular expressions) tutorial on the net
This will replace all html tags from the input string i.e str
alert(str.replace(/<([a-z]*)>(.*)<\/\1>/i, "$2"));
1 2 3
1. Tag match
2. The string which need to retain.
3. End tag match (back references)
Thanks

"all html tags"?
This should have said ANY (single) opening and closing html tag
pair...
>
That converted:
<html><body><b>Hello World!</b></body></html>
to
<body><b>Hello World!</b></body>

Shoud it convert it to just:
Hello World
Feb 4 '08 #5

P: n/a
On 4 ζΕΧ, 16:41, GArlington <garling...@tiscali.co.ukwrote:
On Feb 4, 2:23 pm, "McKirahan" <N...@McKirahan.comwrote:
"Amrit Ranjan" <amri...@gmail.comwrote in message
news:b2**********************************@i72g2000 hsd.googlegroups.com...
On Feb 4, 6:12 pm, GArlington <garling...@tiscali.co.ukwrote:
On Feb 4, 1:03 pm, nithicor...@gmail.com wrote:
Hi,
How to replace a tag by space.
Example:
var str="<b>abcd</b>";
i need a str with "abcd";
replace <band </bby ""
See RegExp (regular expressions) tutorial on the net
This will replace all html tags from the input string i.e str
alert(str.replace(/<([a-z]*)>(.*)<\/\1>/i, "$2"));
1 2 3
1. Tag match
2. The string which need to retain.
3. End tag match (back references)
Thanks
"all html tags"?

This should have said ANY (single) opening and closing html tag
pair...
That converted:
<html><body><b>Hello World!</b></body></html>
to
<body><b>Hello World!</b></body>
Shoud it convert it to just:
Hello World
Other version. Just extending String object.
String.prototype.stripTags = function(aRep)
{
return this.replace(/<[^>]+(?:\/[^>]*)?>/g,aRep);
}
var mystring = "<b>test</b<i>second test</i>";
alert(mystring.stripTags(" "));
Feb 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.