Shoutbox

[ScriptingHelp] Match Whole Words Only - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [ScriptingHelp] Match Whole Words Only (/showthread.php?tid=71975)

[ScriptingHelp] Match Whole Words Only by garfieldman on 02-21-2007 at 12:56 AM

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. :-/

RE: [ScriptingHelp] Match Whole Words Only by CookieRevised on 02-21-2007 at 01:00 AM

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 ?


RE: [ScriptingHelp] Match Whole Words Only by garfieldman on 02-21-2007 at 01:04 AM

wow, I overcomplicated things... :P

Thanks for the help, and the quick reply. :)