The JavaScript function for String Replace replaces the first occurrence
in the string. The function is similar to the php function
str_replace and takes two simple parameters. The first parameter is the
pattern to find and the second parameter is the string to
replace the pattern with when found. The javascript function does not
Replace All...
str = str.replace(”find”,”replace”)
To
ReplaceAll you have to do it a little differently. To replace
all occurrences in the string, use the g modifier like this:
str = str.replace(/find/g,”replace”)
트랙백 주소 :: http://www.voiceportal.co.kr/532/trackback/
-
황상범 2009/04/10 14:07 답글수정삭제잘 썼습니다.
그런데, 저의 경우는 버그가 있네요. 수정해 봅니다.
str = str.replace(/find/g,”replace”)
위에서 찾는 문제에 각괄호를 해 줍니다.
alert("|222222|33333|24444|5555".replace(/[|]/g,"<br>"))
아마도 'or'로 읽혀지는 "|" 기호를 사용해서 그런 것이 아닌가 생각해 봅니다.
잘 쓰겠습니다. -
-








