[JavaScript] 문자열제거 정규표현식
JavaScript 자바 스크립트 문자열제거 정규표현식
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function aa(){
var a = ',,ddddd""';
alert("원본 >> "+a);
alert('"제거 >> '+a.replace(/\"/g,''));
alert(",제거 >> "+a.replace(/\,/g,''));
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="aa();">
</BODY>
</HTML>
※ 응용 (참고)
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/gi, "");
}
String.prototype.replaceAll = function(str1, str2){
var temp_str = "";
if (this.trim() != "" && str1 != str2){
temp_str = this.trim();
while (temp_str.indexOf(str1) > -1){
temp_str = temp_str.replace(str1, str2);
}
}
return temp_str;
}
// 앞,뒤 공백문자 제거 및 캐리지 리턴 문자 제거
function trimStr(str){
return str.replace(/(\s+$)/g, '').replace(/(^\s*)/g, '').replace("\n", '').replace("\r", '');
}