JavaScript negative lookbehind issue

后端 未结 3 1497
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 19:51

I\'ve got some JavaScript that looks for Amazon ASINs within an Amazon link, for example

http://www.amazon.com/dp         


        
3条回答
  •  一个人的身影
    2021-01-20 20:43

    You need to use a lookahead to filter the /e/* ones out. Then trim the leading /e/ from each of the matches.

    var source; // the source you're matching against the RegExp
    var matches = source.match(/(?!\/e)..\/[A-Z0-9]{10}/g) || [];
    var ids = matches.map(function (match) {
      return match.substr(3);
    });
    

提交回复
热议问题