What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Regex with Variables

Regex with Variables
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Regex with Variables
It's because you have to escape the parentheses around the gamer tag with a backslash, but as you're creating a RegExp with a string, you first have to escape the backslash itself too. :P
code:
var XBG = NewPsm.match(new RegExp("Xbox 360: (.*?) \\(" + X360GamerTag + "\\)", "i"))[1];
The reason for this is if you don't escape the parentheses, it'll capture what's between those too:
code:
Resulting RegExp: Xbox 360: (.*?) (Stefan Leroux)
Result:
  [0] = Xbox 360: Sonic The Hedgehog 2 Stefan Leroux
  [1] = Sonic The Hedgehog 2
  [2] = Stefan Leroux
  • The matched part is stored at index 2, even when you already knew that part as you provided that data yourself!
  • It won't look for parentheses, it looks for "Stefan Leroux" immediately after "Sonic The Hedgehog 2".
So what did we learn today? Escape any characters which can be interpreted by the regular expression engine as special characters. :)

As for your second question: check if "reply" is null first before checking "reply[1]". That should do the trick. :)

This post was edited on 11-21-2008 at 04:48 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-21-2008 04:41 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Regex with Variables - by ArkaneArkade on 11-19-2008 at 06:05 AM
RE: Regex with Variables - by Mnjul on 11-19-2008 at 10:32 AM
RE: Regex with Variables - by ArkaneArkade on 11-19-2008 at 12:26 PM
RE: Regex with Variables - by ArkaneArkade on 11-19-2008 at 11:36 PM
RE: Regex with Variables - by andrewdodd13 on 11-20-2008 at 08:29 AM
RE: Regex with Variables - by ArkaneArkade on 11-20-2008 at 04:13 PM
RE: Regex with Variables - by ArkaneArkade on 11-21-2008 at 07:08 AM
RE: Regex with Variables - by Matti on 11-21-2008 at 04:41 PM
RE: Regex with Variables - by ArkaneArkade on 11-22-2008 at 11:51 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