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

Regex syntax problems?
Author: Message:
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
O.P. Regex syntax problems?
I was fixing my code for aNILEators emoticons and apparently Plus! doesn't like the syntax of the regex I made Error: Syntax error in regular expression (code: -2146823271).  I couldn't see anything wrong with it so I thought I'd use regex coach (like we use with work) and it said everything was caturing correctly.  I realise it is made more for perl than JScript, but there is nothing in it that should make an difference (perl is the one which is less lenient).  So I've come to the conclusion that there is something wrong with Plus!'s error checking.  I asked Cookie to check it out but I guess he has had no time, and I've been busy doing holiday stuff with the family.  If anyone would like to give it a go here is the code that I used.

code:
var emails = new Array("email.address@gmail.com");
var re = new RegExp(":(?:|[DOP()$@S]|-[#*])|\((?:[6e~#r*d&@lkfwz%]|co?|au?|[ima]p?|um?|x{1,2}|yn?|h5?|s[nto]?|pi?|tu?|[nb](?:ah)?|brb|\{\)\(\})\)|8(?:-|o)\||\^o\)|\+o\(","gi");
function OnEvent_ChatWndSendMessage(pChatWnd,sMessage){
    for(i in emails){
        if (Messenger.MyUserId == emails[i]){
            return sMessage.replace(re,function($1){
                Debug.Trace($1);
                if($1.charAt(0) === ":"){
                    $1.replace(/:-?/,"=");
                }else if($1.charAt(0) === "("){
                    $1.replace(/\(|\)|\*|&/g,function($1){
                    Debug.Trace($1);
                        switch($1){
                            case "(": return "{";
                            case ")": return "}";
                            case "*": return "*2";
                            case "&": return "dog";
                        }
                    });
                }else{
                    switch($1){
                        case "8-|": return "8o)";
                        case "^o)": return "=/";
                        case "\+o(": return "=o(";
                        case "8o|": return "=o|";
                    }
                }
            });
        }
    }
}

Also for those interested, Regex Coach.

If ou don't understand the regex then you probably will not understand how to find the problem, I'm sorry to be so blunt but it is not easy (at least I took away the look behinds :P).

The regex is to capture all of the default emoticons that are changed with aNILEator's emoticons and is stored in the re variable (line 2).

Thanks to anyone who can track this down, normall I would do a better jo at my bug report, but you know how it is with holidays and borrowing internet :P

This post was edited on 03-30-2008 at 08:08 AM by markee.
[Image: markee.png]
12-22-2007 12:14 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Regex syntax problems?
Escape your backslashes. :p

quote:
Originally posted by http://www.regular-expressions.info/javascript.html
I recommend that you do not use the RegExp constructor with a literal string, because in literal strings, backslashes must be escaped. The regular expression \w+ can be created as re = /\w+/ or as re = new RegExp("\\w+"). The latter is definitely harder to read. The regular expression \\ matches a single backslash. In JavaScript, this becomes re = /\\/ or re = new RegExp("\\\\").
12-22-2007 08:37 PM
Profile PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
O.P. RE: Regex syntax problems?
Haha thanks.

* markee feels like a nub
[Image: markee.png]
12-23-2007 09:01 AM
Profile 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