¾È±Ô °øºÎ¹æ

Javascript & JQuery & CSS > JQuery Á¤±Ô½Ä - Á¤±Ô½ÄÀ» ÀÌ¿ëÇÑ Replace ¹æ¹ý

µî·ÏÀÏ : 2017-07-14 17:30 Á¶È¸¼ö : 53,458

Replace()¿¡¼­ ġȯÀ» ´ç´ãÇϴ°ÍÀº, Á¤±Ô½ÄÀÇ g ºÎºÐÀÌ´Ù. ÇØ´çÀ§Ä¡¿¡ ¿À´Â ¹®ÀÚ¿¡ µû¶ó¼­

g : ¹®ÀÚ¿­ ³»ÀÇ ¸ðµç ÆÐÅÏ Ã¼Å©

i : ´ë¼Ò¹®ÀÚ¸¦ ±¸º°ÇÏÁö ¾ÊÀ½

m : ¿©·¯ÁÙ¿¡ °ÉÃļ­ üũ

À§¿Í °°Àº ¶æÀÌ µÈ´Ù.



$('el').val().replace();

¹®ÀÚ¿­ º¯¼öÀÇ Æ¯Á¤ ¹®ÀÚ¸¦ Á¦°ÅÇϰųª ¸ðµç °ø¹éÀ» ¾ø¾Ù ¶§ »ç¿ë.

¾Æ·¡´Â Á¤±Ô½ÄÀ» È°¿ëÇÑ Æ¯Á¤ ¹®ÀÚ Á¦°Å ¹æ¹ý.

.replace(' ','')          : ù¹ø° °ø¹é Á¦°Å

.replace(/\-/g,'')        : ƯÁ¤¹®ÀÚ Á¦°Å1 (-)

.replace(/,/g,'')         : ƯÁ¤¹®ÀÚ Á¦°Å2 (,)

.replace(/^\s+/,'')       : ¾ÕÀÇ °ø¹é Á¦°Å

.replace(/\s+$/,'')       : µÚÀÇ °ø¹é Á¦°Å

.replace(/^\s+|\s+$/g,'') : ¾ÕµÚ °ø¹é Á¦°Å

.replace(/\s/g,'')        : ¹®ÀÚ¿­ ³»ÀÇ ¸ðµç °ø¹é Á¦°Å

.replace(/\n/g,'')        : °³Çà Á¦°Å

.replace(/\r/g,'')        : ¿£ÅÍ Á¦°Å


var str = '¾È³ç         ÇϽŰ¡¿©?';
str.replace( /(\s*)/g, "" ); : Àüü °ø¹éÁ¦°Å ¹æ¹ý

$.trim(str); : jQuery °ø¹éÁ¦°Å


¿¹Á¦)


1. "asdf-asdf-fsdddf".replace(/[-]/gi, "@"); => asdf@asdf@fsdddf

2. "asdf/.asdf/.fsdddf".replace(/[/.]/gi, "@"); => asdfasdffsdddf

3. "asdf/.asdf/.fsdddf".replace(/\/./gi, "@"); => asdf@asdf@fsdddf

4. "4asdf/.asdf/.fsdd4df".replace(/[/4.]/gi, "@"); => @asdfasdffsdd@df

* Ư¼ö±âÈ£¸¦ ¸ÇóÀ½ ÀûÀ»¶§´Â Ç×»ó "\" À̺κÐÀÌ Á¤±Ô½Ä ¸Ç¾Õ¿¡ Á¸ÀçÇؾßÇÔ

Ex) document.form.object_nm.value.replace(/\,/g, "@");

* À§ ¿¹Á¦¿¡¼­ 2, 3 ¹øÀÇ Â÷À̸¦ Àß ÆľÇÇØ¾ß ÇÑ´Ù,

2 ¹øÀº []¾È¿¡ Ư¼ö±âÈ£¸¦ ÇϳªÇϳª °³º°ÀûÀ¸·Î º¯È¯,
3 ¹øÀº Ư¼ö±âÈ£¸¦ ÇϳªÀÇ ¹­À½À¸·Î ÀνÄÇؼ­ º¯È¯
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.