RegExp.exec遇到的问题

 

const _reg:RegExp = new RegExp("/cgi-bin/.*?g_tk=","g");

var url:String = "http://card.show.qq.com/cgi-bin/card_badge_info?g_tk=963795748";

 

var cgi:String = _reg.exec(url);//getCgi(url);

trace("cgi1"+cgi);

 

var url2:String = "http://card.show.qq.com/cgi-bin/card_badge_info?g_tk=963795748";

var cgi2:String = _reg.exec(url2);//getCgi(url);

trace("cgi2"+cgi2);


cgi1   /cgi-bin/card_badge_info?g_tk=
cgi2   null

解决方案:
1:正则不用g
2: 初始化正则的lastIndex

你可能感兴趣的:(RegExp)