Login

Language :
TitleJavaScript replace 함수 내 정규식에서 eval 및 변수 활용 (중복된 글자 제거)
Utilize variable and eval function in regular expression in JavaScript replace function (Remove duplicate characters)
Writer이지섭Write DateDec 31 2019Modify DateDec 31 2019View Count1739

A method of creating regular expressions using variable and eval function in the JavaScript replace function.

- Remove duplicate characters - 

 

<script type="text/javascript">
var c = "12,34,,567,8,,,,90";
var d = ",";
var e = c.replace(eval("/" + d + "" + d + "/g"), d);
while (e.indexOf(d + "" + d) > -1) {
e = e.replace(eval("/" + d + "" + d + "/g"), d);
}
document.writeln(e); </script>

 

Result :

12,34,567,8,90

Comment

Name               Password 
Content
Check Password.

Please enter your password when registering your comment.