regex - Javascript: Replace one or more identical characters with the same number of another character? -
i need escape special characters js string, can replace 1 or more occurrences single character.
for example, want replace & &
when escape string: &&&
&&&
.
i've been using
input = input.replace(/&/g,"&");
i know solution problem has using anonymous function, need escape 10 other characters. can't see way pass replacement variable function. mean i'll have write 11 separate functions?
your code okay, seems have tested without /g
.
you can use: replace(/(&)/g,"$1amp;");
see , test code here.
Comments
Post a Comment