开发者

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

开发者 https://www.devze.com 2023-02-24 21:36 出处:网络
I\'m not a 开发者_JS百科JS guru, but could someone help me find the invalid quantifier error in the following snippet?

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

精彩评论

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