Regex with Variables - 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: Regex with Variables (/showthread.php?tid=87357) Regex with Variables by ArkaneArkade on 11-19-2008 at 06:05 AM
Hey guys, jscript code:However, since I intend to add a lot more options for hte ids, I'm looking for a way to get them in the regexp as the variable, but I don't understand how that would be done, since I'm confused enough by the lack of quotes. Can anyone help me? Cheers as always guys, Leroux RE: Regex with Variables by Mnjul on 11-19-2008 at 10:32 AM
You can use normal strings as the constructor parameters of RegExp. jscript code: RE: Regex with Variables by ArkaneArkade on 11-19-2008 at 12:26 PM Thats absolutely perfect Mnjul, thank you so much. RE: Regex with Variables by ArkaneArkade on 11-19-2008 at 11:36 PM
Here was me thinking I'd manage ok for the rest of today, but no, more confusion. html code: I tried new RegExp("<li>Filename. * ?)", "i")); for it, but that doesnt work, because the ? make it take nothing since theres no ending match. Any possibilites? RE: Regex with Variables by andrewdodd13 on 11-20-2008 at 08:29 AM Either detect the new line "\n", or detect the next <li> tag and... ah. You can detect the next <li> tag, and trim it from the string. But if you're doing a global match you will run into some problems. RE: Regex with Variables by ArkaneArkade on 11-20-2008 at 04:13 PM
Cheers man. RE: Regex with Variables by ArkaneArkade on 11-21-2008 at 07:08 AM
Now I've got another problem, and I don't have a clue what it is this time. jscript code:As far as I can figure, this should give me the game name, as it has a leading and ending space. It just gives me a null or not an object in debug. Even stranger is I changed it to remove the space between (.*?) and (, and this works, buts gives me a result of "Sonic The Hedgehog 2 (", including the (, which should be regexed out. I've also tried \escaping the ( and ), but that just gave me the same error as the first. Anyone able to tell me what I'm doing wrong? - Q2) Slightly off topic, but I didn't want to start a new post. How can I detect if an array has data? I have a variable being set to regex, so I'm looking to set reply[1], but if there is no match, it just breaks. I've tried if (reply[1]!==null) but it still gives me a debug of 'null' is null or not an object. RE: Regex with Variables by Matti on 11-21-2008 at 04:41 PM 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. code:The reason for this is if you don't escape the parentheses, it'll capture what's between those too: code:
As for your second question: check if "reply" is null first before checking "reply[1]". That should do the trick. RE: Regex with Variables by ArkaneArkade on 11-22-2008 at 11:51 AM Cheers Matti. Everything working great now, except for me I don't really understand why you need to escape a backslash to escape bracket, but not matter - either way I got it working now. |