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

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

只匹配白色空格而不是選項(xiàng)卡,回車符或Javascript中的謊言源的正則表達(dá)式

只匹配白色空格而不是選項(xiàng)卡,回車符或Javascript中的謊言源的正則表達(dá)式

猛跑小豬 2022-08-18 10:06:05
我想格式化一個(gè)沒有多個(gè)空格的字符串。字符串可以具有制表符、回車符或換行符。示例 1:expacted 結(jié)果:helloworldhelloworld示例 2:預(yù)期結(jié)果:“hello world”hello        worldconst formatString = (s) => {  const trimmed = s.trim();  const formated = trimmed.match(/\s/g)  return s.trim().replace(/\s+/g, ' ')}const str = `helloworld`const result = formatString(str)console.log(result)
查看完整描述

1 回答

?
四季花海

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

你可以使用空間(精確)。容易


const formatString = (s) => {

  return s.replace(/ +/g, " ");

};


let str = `hello

world`;

const result = formatString(str);

console.log(result);

str = `hello    world`;


console.log(formatString(str));


使用正則表達(dá)式:


const formatString = (s) => s.replace(/[^\S\r\n]+/g, " ");


console.log(

  formatString(`hello

world`)

);

console.log(formatString(`hello     world`));


查看完整回答
反對(duì) 回復(fù) 2022-08-18
  • 1 回答
  • 0 關(guān)注
  • 72 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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