Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用香草Javascript提取HTTP URL?_Javascript_Regex - Fatal编程技术网

如何使用香草Javascript提取HTTP URL?

如何使用香草Javascript提取HTTP URL?,javascript,regex,Javascript,Regex,我想先提取URLhttps://example.com/ccm/resource/itemName/com.ibm.team.workitem.Attachment/72306使用vanilla Javascript从以下字符串获取 var-str=''; var模式=/^http(.*)(“)/g; var match=pattern.exec(str); 警报(匹配);这不是正则表达式,但这里有一个解决方案: var-str=''; var url=str.split('href=')[

我想先提取URL
https://example.com/ccm/resource/itemName/com.ibm.team.workitem.Attachment/72306
使用vanilla Javascript从以下字符串获取

var-str='';
var模式=/^http(.*)(“)/g;
var match=pattern.exec(str);

警报(匹配);
这不是正则表达式,但这里有一个解决方案:

var-str='';
var url=str.split('href=')[1]。子字符串(1)。split('“')[0];

警报(url)
DOM是普通的javascript,应该让您比regex更容易地选择链接的
href
属性;你介意这样的解决方案吗
document.getElementById(“jazz\u ui\u ResourceLink\u 23”)。href
能否在旁边显示类似URL的字符串this@Aaron谢谢,但我无法通过唯一ID识别元素。