請,我需要幫助來洗掉字串中包含三個或更少字符的任何單詞。
這是我的代碼
let text = "The best things in life are free";
let result = text.replace(/^[a-zA-Z]{3}{2}{1}$/, '');
我的預期結果應該是:
“最好的東西生活免費”
uj5u.com熱心網友回復:
我不認為這需要regex,只需用 a 和大于 3 分開,space然后再用afilterlengthjoinspace
let text = "The best things in life are free";
let result = text.split(' ').filter(i => i.length > 3).join(' ');
console.log(result)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/504709.html
標籤:javascript 反应 细绳
