2011-03-26 5 views
0

이중 복사를 제거하기 위해 스크립트를 사용했습니다. 그러나이 스크립트는 공간과 함께 새 줄을 제거합니다.이중 줄은 제거하지만 새 줄은 지우지 않습니다.

Suppose Input is "\s\s\n\n" 
Script's output is "\s" 
Desired Output "\s\n\n" 

That I simply want to remover double space but not new line. 
Want to skip new line.
당신은 공백을 expunges \s을 사용하고

function clean(f) { f.value=f.value.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' '); return true; }

+1

'\ s'는 \ t \ 없음의 \의 V \ F \ r''일치합니다. https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp#endnote_equivalent_s –

+0

'\ s'는 공백 문자 (문자 이스케이프 섹션 참조)] (http://www.javascriptkit.com /javatutors/redev2.shtml), 줄 바꿈, 탭, 세로줄, 줄 바꿈,'' '등이 있습니다. – jswolf19

답변

2

. 다음 모든 \n 당신이 사용할 수있는 유지하는 동안 두 배 이상 공백을 제거하려면 :

replace(/ {2,}/g,'') 
관련 문제