主要不理解,不知道举什么例子好,就用这个,如果有好的更好<script type="text/javascript">
str = "For more information, see Chapter 3.4.5.1, seeChapter 4.6.7.8";
re = /(chapter \d+(\.\d)*)/i;
found = str.match(re);
document.write(found);
</script>
记得好像就是match在g的情况下有区别,exec就第一次匹配 但match比较混...希望大家能清楚解析下.

解决方案 »

  1.   

    http://makemyownlife.javaeye.com/blog/395172
      

  2.   

    对于global来说
    match一次找到所有匹配元素。存到数组中
    exec每执行一次向后匹配一次,将此次匹配存到数组,数组中是匹配和所有子匹配的值,
    不是global
    match找到匹配和子匹配存到数组中
    str = "For more information, see Chapter 3.4.5.1, seeChapter 4.6.7.8";
    re = /(chapter \d+(\.\d)*)/gi;
    found = str.match(re);
    for(var i=0;i<found.length;i++){
      alert(found[i]);
    }
    re = /(chapter \d+(\.\d)*)/gi;
    while ((found = re.exec(str)) != null){
       alert(found[0]);
    }
      

  3.   

    exec可以匹配母串中的所有匹配。返回这个值,而match直接返回数组。