從字串中獲取src值的正確搜索引擎。
。 var str = "<iframe width="1000& quot; height=& quot;460& quot; src=" https& #58;/myvideo. dpdhl.com/video/CuEt8XJ8uVEU3MZrjQp5z" title="新組件測驗視頻"></iframe>" ;
var re = /^src/g;
var n = str.match(re)。
console.log(n);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
//輸出 "https://myvideo.dpdhl.com/video/CuEt8XJ8uVEU3MZrrjQp5z"title="新組件的測驗視頻"></iframe>
uj5u.com熱心網友回復:
我們可以嘗試使用match與regex模式src=S :
var str = "<iframe width=& quot;1000& quot; height=& quot;460& quot; src=& quot; https& #58;/myvideo. dpdhl.com/video/CuEt8XJ8uVEU3MZrjQp5z" title="新組件測驗視頻"></iframe>" ;
var src = str.match(/src=S /)。
console.log(src);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
如果你知道你的輸入總是像這樣或類似,你也可以直接使用replace:
const str = "<iframe width=& quot;1000& quot; height=& quot; 460& quot; src=& quot; https& #58;/myvideo. dpdhl.com/video/CuEt8XJ8uVEU3MZrjQp5z" title="新組件測驗視頻"></iframe>" ;
const src = str.replace(/^.*? src=" (.*?)".*?$/, "$1"/span>) 。
console.log(src);
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/323767.html
標籤:
