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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Javascript Regex matchAll 函數(shù)不起作用

Javascript Regex matchAll 函數(shù)不起作用

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

2 回答

?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

如果需要matchAll,請(qǐng)?jiān)谥С值那闆r下使用它:


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]);

}


查看完整回答
反對(duì) 回復(fù) 2022-12-29
?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

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

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


查看完整回答
反對(duì) 回復(fù) 2022-12-29
  • 2 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)