What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help]Returning the inside of a string...

[Help]Returning the inside of a string...
Author: Message:
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: [Help]Returning the inside of a string...
quote:
Originally posted by Pai
To extract the inside of [tag]hi[/tag]:

code:
var tagInside = tags.replace(/\[tag\]|\[\/tag\]/gi,"");

result: tagInside contains "hi"
thats a horrible way IMO , what happens if the string isnt just "[tag]hi[/tag]" we should use regular expressions and use String::match

code:

var Message = "the cow goes [b]moo[/b] in the morning";

//now theres a few things we can do... extract the text like so...
var text = Message.match(/\[b\](.*?)\[\/b\]/g);

/* text is an array
text[0] will contain the full matched string eg [b]moo[/b]
text[1] will contain the first match eg moo

if there was another match it would be in text[2] and so on...
*/


//we could replace the [b] tags with other tags eg <b>

Message = Message.replace(/\[b\]/g, "<b>");
Message = Message.replace(/\[\/b\]/g, "</b>");





A few helpful links
A regexp index
A regexp tuturial
Another regexp tuturial
Another regexp Tutorial ment for php but theres alot of useful information there

[Image: dt2.0v2.png]      Happy Birthday, WDZ
07-13-2006 03:13 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help]Returning the inside of a string... - by andrewdodd13 on 07-12-2006 at 05:11 PM
RE: [Help]Returning the inside of a string... - by Pai on 07-12-2006 at 06:01 PM
RE: [Help]Returning the inside of a string... - by -dt- on 07-13-2006 at 03:13 AM
RE: RE: [Help]Returning the inside of a string... - by Pai on 07-13-2006 at 08:32 AM
RE: [Help]Returning the inside of a string... - by Silentdragon on 07-13-2006 at 09:56 AM
RE: [Help]Returning the inside of a string... - by -dt- on 07-13-2006 at 10:07 AM
RE: [Help]Returning the inside of a string... - by Pai on 07-13-2006 at 11:21 AM
RE: [Help]Returning the inside of a string... - by andrewdodd13 on 07-13-2006 at 11:33 AM


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