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:
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
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[RESOLVED] Need help with JavaScript replace() - by macgyver08 on 01-28-2010 at 11:03 AM
RE: Need help with JavaScript replace() - by stoshrocket on 01-28-2010 at 12:18 PM
RE: Need help with JavaScript replace() - by macgyver08 on 01-28-2010 at 01:18 PM


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