Shoutbox

Regex syntax problems? - 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 syntax problems? (/showthread.php?tid=80326)

Regex syntax problems? by markee on 12-22-2007 at 12:14 PM

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

RE: Regex syntax problems? by WDZ on 12-22-2007 at 08:37 PM

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("\\\\").

RE: Regex syntax problems? by markee on 12-23-2007 at 09:01 AM

Haha thanks.

* markee feels like a nub