我想格式化一個(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)
只匹配白色空格而不是選項(xiàng)卡,回車符或Javascript中的謊言源的正則表達(dá)式
猛跑小豬
2022-08-18 10:06:05