tyler jones
07-04-2002, 01:34 PM
I have this trimming function that is supposed to replace 2 or more instances of spaces with a single space. However, it's also replacing new line characters. Is there a way in regular expressions that I can say, replace 2 or more spaces, but not new line characters? Here's my code. Thanks.
function removeSpaces( str )
{
var regExp = /\s{2,}/gi;
if ( regExp.test( str )) {
str = str.replace(regExp,' ');
}
return str;
}
... and my str may hold the value...
tyler jones
1110 main st nw
st. petersburg, fl 12345
tj@tj.com
function removeSpaces( str )
{
var regExp = /\s{2,}/gi;
if ( regExp.test( str )) {
str = str.replace(regExp,' ');
}
return str;
}
... and my str may hold the value...
tyler jones
1110 main st nw
st. petersburg, fl 12345
tj@tj.com