I have a jQuery selector which gets the html
within a selector, like so:
$('.pp-product-description .noindent').html()
Here's an example of the output, I've verified that it's a 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>
I'm trying to trim this down so that the \r
, \n
and \t
characters disappear. I'm currently using nodeJS
' validate
module which has a special sanitize(string).trim()
command which should trim away white space. From the docs:
var str = sanitize(' \t\r hello \n').trim(); //'hello'
This has worked for me in the past, but here it isn't. I've also tried javascript's built in trim()
method, as well as str.replace("\s+", "");
, none are working.
Any ideas on what I'm missing, or what I can do to get this working?
I have a jQuery selector which gets the html
within a selector, like so:
$('.pp-product-description .noindent').html()
Here's an example of the output, I've verified that it's a 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>
I'm trying to trim this down so that the \r
, \n
and \t
characters disappear. I'm currently using nodeJS
' validate
module which has a special sanitize(string).trim()
command which should trim away white space. From the docs:
var str = sanitize(' \t\r hello \n').trim(); //'hello'
This has worked for me in the past, but here it isn't. I've also tried javascript's built in trim()
method, as well as str.replace("\s+", "");
, none are working.
Any ideas on what I'm missing, or what I can do to get this working?
Share Improve this question asked Aug 19, 2013 at 7:05 JVGJVG 21.2k48 gold badges140 silver badges215 bronze badges 3 |1 Answer
Reset to default 26http://jsfiddle.net/HkJbr/....
.replace(/[\n\t\r]/g,"")
trim
won't do anything, and the regex you tried is a string not a regex, so that won't do anything either... – elclanrs Commented Aug 19, 2013 at 7:07.replace()
just returns a replaced string. You need to dostr = str.replace(...)
. – Teemu Commented Aug 19, 2013 at 7:28