2.3. javascript中正则表达式用法举例

例 2.1. Javascript中match的用法举例

//提取skydrive共享地址中的resid(resource id)
shareAddrStr = "https://skydrive.live.com/redir?resid=9A8B8BF501A38A36!1578";
//shareAddrStr = "https://skydrive.live.com/redir.aspx?cid=9a8b8bf501a38a36&resid=9A8B8BF501A38A36!1578";
var residRe = /resid=(\w+!\d+)/;
var foundResid = shareAddrStr.match(residRe);
if(!foundResid){
    alert("貌似你输入的Skydrive共享地址有误,请确认输入了正确的地址!");
    skydriveShareAddr.focus();
    return false;
}

var resid = foundResid[1];//此处可以获得对应的resid=9A8B8BF501A38A36!1578
        

另外,match返回的结果foundResid,对应的也是foundResid[0]表示所匹配的字符串的整体,此处为: