我有一个如下所示的JavaScript 字符串:
Thanks for choosing our services (https://servicesnow.com)!! Download receipt <https://support.com/site/voucher?email=vrome@OkopRI.SG&hash=2f95f5d774e44f6543c74fcc4e235f8b8eb9cf>
我想找到一个提取收据链接的正则表达式:
https://support.com/site/voucher?email=vrome@OkopRI.SG&hash=2f95f5d774e44f6543c74fcc4e235f8b8eb9cf
到目前为止,我尝试过的是:.match(/ \ b(https?://.* ?. [a-z] {2,4} \ b)/ g);
,但不幸的是,它与第一个http匹配。我怎样才能做到这一点?谢谢
答案 0 :(得分:2)
就这么简单
var string = "Thanks for choosing our services (https://servicesnow.com)!! Download receipt <https://support.com/site/voucher?email=vrome@OkopRI.SG&hash=2f95f5d774e44f6543c74fcc4e235f8b8eb9cf>";
var url = string.match(/\<(.*)\>/).pop();
console.log(url);
您可以使用<和>字符作为分隔符。