【发布时间】:2018-06-17 18:36:23
【问题描述】:
我正在尝试替换 massive string 中的所有“formattedTime”实例。 这是我的代码
googleTrends.interestOverTime({keyword: selectedTopic})
.then((results) => {
results.replace(/formattedTime/g, 'no what the heck');
console.log(results);
})
.catch((err) => {
console.error('Oh no there was an error', err);
});
我没有收到任何错误,但是我的控制台内没有发生任何事情。 我什至尝试替换一个单行字符串,但它都不起作用。可能是因为我收到的承诺? 我对 RegEx 比较陌生,所以我认为这可能是一个问题,但似乎不是。
【问题讨论】:
-
replace() 方法在字符串中查找指定值或正则表达式,并返回替换指定值的新字符串;从而更新或返回结果。
标签: javascript regex replace promise