What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [ScriptingHelp] Match Whole Words Only

[ScriptingHelp] Match Whole Words Only
Author: Message:
garfieldman
New Member
*


Posts: 5
– / Male / –
Joined: Feb 2007
O.P. [ScriptingHelp] Match Whole Words Only
Any help for this amateur scripter will be much appreciated... :)

Kind of for practice, I'm testing a simple script where certain words in a message are automatically replaced by other words. (You know, just like the Quick Text function in Messenger Plus!)

So I got the replacing function down, but I can't seem to figure out, with my limited intelligence, how to make it so that it replaces whole words only.

so for example-
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
if (Message.search("Whatever") !== -1)
return Message.replace("Whatever","Test")
}

so now how do I make it so that the script only replaces "Whatever" with "Test" if "Whatever" is a whole word. Like, so "Whateverasfkl" wouldn't become "Testasfkl"? I've thought that perhaps it's using the split() string (Message.split(" "), but for all I'm worth I can't figure it out. :-/

This post was edited on 02-21-2007 at 12:57 AM by garfieldman.
02-21-2007 12:56 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [ScriptingHelp] Match Whole Words Only
Forget using split() and all other things. Study and use the regular expression object... ;)

For starters, download and read the JScript 5.6 Documentation > "Regular Expression Object" and "Regular Expression Syntax"

There are also many threads on these forums which are about regular expressions, including snippets of code which will do what you want.

Search the Scripting forum for ".replace("...
eg:
* CookieRevised's reply to how do i replace this text?
* CookieRevised's reply to [Question] Isn't string.replace supposed to replace all occurences ?

This post was edited on 02-21-2007 at 01:05 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-21-2007 01:00 AM
Profile PM Find Quote Report
garfieldman
New Member
*


Posts: 5
– / Male / –
Joined: Feb 2007
O.P. RE: [ScriptingHelp] Match Whole Words Only
wow, I overcomplicated things... :P

Thanks for the help, and the quick reply. :)
02-21-2007 01:04 AM
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