从javascriptstring修剪\ n,\ s,\ t
我有一个jQueryselect器,它在select器中获取html
,如下所示:
$('.pp-product-description .noindent').html()
这是一个输出示例,我已经validation它是一个string:
<li class="standardBulletText">600 fill power down adds warmth without weight</li> \r\n\t\t\t\t\t\t \t <li class="standardBulletText">Matte shell with DriOff™ finish for water-resistant protection</li>\ r\n\t\t\t\t\t\t \t <li class="standardBulletText">Snap-off, adjustable hood with removable faux fur trim</li> \r\n\t\t\t\t\t\t \t<li class="standardBulletText">Hidden zip/snap closure except for top and bottom snaps</li>
我正在尝试修剪,以便\r
, \n
和\t
字符消失。 我目前正在使用nodeJS
' validate
模块 ,它有一个特殊的sanitize(string).trim()
命令应该修剪掉空白。 从文档:
var str = sanitize(' \t\r hello \n').trim(); //'hello'
这在过去对我是有效的,但是这不是。 我也试过用trim()
方法构build的javascript,以及str.replace("\s+", "");
,没有人在工作。
任何想法,我什么想念,或者我能做些什么来得到这个工作?
.replace(/[\n\t\r]/g,"")