learningProcess icon indicating copy to clipboard operation
learningProcess copied to clipboard

使用正则实现trim()函数

Open shimuash opened this issue 8 years ago • 0 comments

function trim(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '')
}
const str = ' string name '
trim(str)  // "string name"

正则表达式这块不怎么熟悉,后面要抽时间再重点学习一下

shimuash avatar Sep 10 '17 10:09 shimuash