开发者

Javascript - invalid quantifier error, can someone help me see my mistake?

I'm not a 开发者_JS百科JS guru, but could someone help me find the invalid quantifier error in the following snippet?

THANKS IN ADVANCE! -mprototype

function $_GET(q,s) {
        s = s ? s : window.location.search;
        var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' );
        return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
    } 


? has a special meaning in Regular Expressions, specifically it makes the preceding item optional. If you are trying to find the question mark character itself you need to escape it with a backslash.

function $_GET(q,s) {
        s = s ? s : window.location.search;
        var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' );
        return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
    } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜