What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [RESOLVED] Need help with JavaScript replace()

[RESOLVED] Need help with JavaScript replace()
Author: Message:
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
34 / Male / Flag
Joined: Feb 2007
O.P. [RESOLVED] Need help with JavaScript replace()
I found a regular expression that will strip my string of every html tag...

code:
var stripped = htmlStr.replace(/(<([^>]+)>)/ig,"");

Well, I also want it to strip every thing between parentheses, square brackets, and replace "&#160;" with a space.

It would be really cool if you could explain how to do this as well, because the stuff in the above code after "replace" confuses me. I have no idea how that's working.

This post was edited on 01-30-2010 at 12:06 AM by macgyver08.
01-28-2010 11:03 AM
Profile E-Mail PM Find Quote Report
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Need help with JavaScript replace()
quote:
Originally posted by macgyver08
I found a regular expression that will strip my string of every html tag...

code:
var stripped = htmlStr.replace(/(<([^>]+)>)/ig,"");

Well, I also want it to strip every thing between parentheses, square brackets, and replace "&#160;" with a space.

It would be really cool if you could explain how to do this as well, because the stuff in the above code after "replace" confuses me. I have no idea how that's working.

the replace function is using Regular Expressions, in the format of /pattern/modifiers. In this example, everything between the "/"s are the characters to replace and the ig are the modifiers (in this case, i for case insensitive and g for global [replaces all instances, not just the first]).

So, you can modify everything between the /'s to strip whatever character you want.

As for replacing "&#160" with a space, just use another replace function...

Javascript code:
var stripped = htmlStr.replace(/(<([^>]+)>)/ig,"");
stripped = stripped.replace(/&#160/g," ");

formerly methos
01-28-2010 12:18 PM
Profile PM Web Find Quote Report
macgyver08
Junior Member
**

Avatar
Hakuna matata!

Posts: 23
34 / Male / Flag
Joined: Feb 2007
O.P. RE: Need help with JavaScript replace()
Thanks a lot! :D
01-28-2010 01:18 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On