var string = " a b | dd gggg"; console.log(string); console.log(string.replace(/ +/g, ' '))
去掉以开头结尾的,
val.replace(/(^,)|(,$)/g,"")