第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Javascript Regex matchAll 函數不起作用

Javascript Regex matchAll 函數不起作用

一只斗牛犬 2022-12-29 16:04:48
每當我運行下面的代碼時,我都會出錯TypeError: responseData.matchAll is not a function     var responseData = response.data.toString();     var regex = new RegExp('(<dbname>)(.*?)(?=<\/dbname>)', 'g');     var matches = responseData.matchAll(regex);    當我matchAll用exec它代替時!但是,我需要使用matchAll. 這真讓我抓狂。謝謝
查看完整描述

2 回答

?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

如果需要matchAll,請在支持的情況下使用它:


var responseData = "<dbname>hhh</dbname>hhh<dbname>hhh3</dbname>"; 

var regex = new RegExp('<dbname>(.*?)(?=</dbname>)', 'g'); 

console.log(Array.from(responseData.matchAll(regex), x=>x[1]));

// => ["hhh","hhh3"]

   


您還可以使用exec:


var responseData = "<dbname>hhh</dbname>hhh<dbname>hhh3</dbname>"; 

var regex = new RegExp('<dbname>(.*?)(?=</dbname>)', 'g'); 

while(match=regex.exec(responseData)){

  console.log(match[1]);

}


查看完整回答
反對 回復 2022-12-29
?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

matchAll很新,它只適用于某些瀏覽器。它適用于 Chrome、FX、Edge 和 Safari,但舊版和移動瀏覽器可能需要 shim/polyfill。

這是一個關于使用填充程序向舊版瀏覽器添加功能的好答案:https ://stackoverflow.com/a/58003501/905


查看完整回答
反對 回復 2022-12-29
  • 2 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號