Go straight to code

<script type="text/javascript">
    var url = "http://www.***.com/n/2013/01/08/1037962.shtml";
    //url = "http://www.***.com/mine/mine_show.aspx?id=1037962";
    var reg = /\/\d+.shtml|\? id\=\d+/gi;
    var result;
    if((result = reg.exec(url)) ! =null){
        result += "";
        var id = result.match(/\d+/g);
        alert(id);
    }
</script>
Copy the code

Refer to the article

www.w3school.com.cn/js/jsref_ob…

\

————————————————————

The following two statements are equivalent: re = new RegExp (” \ \ w + “, “gi”) re = / \ w + / gi \