replace()

string.replace(searchValue, replaceValue)

var result ="mother_in_low".replace("_", "-"); 
result //  "mother-in_low"

“mother-in_low”   처럼 실망스런 결과가 나온다.

searchValue 가 정규표현식이고 g 플래그가 설정된 경우라면 일치하는 모든 부분이 교체 됩니다.

var result ="mother_in_low".replace(/_/g, "-");
result //  "mother-in-low"
Total Views: 3460 ,

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.