Ä¿ÇǴнº, ½Ã½ºÅÛ ¿£Áö´Ï¾îÀÇ ½°ÅÍ Ä¿ÇÇÇâÀÌ ³ª´Â *NIX
Ä¿ÇǴнº
½Ã½ºÅÛ/³×Æ®¿÷/º¸¾ÈÀ» ´Ù·ç´Â °÷
* HanIRCÀÇ #coffeenix ¹æ
[ Àåºñ ¹× ȸ¼± ÈÄ¿ø ]
HOME > ÇÁ·Î±×·¡¹Ö / °³¹ß µµ¿ò¸»
°Ë»ö : »çÀÌÆ® WHOIS À¥¼­¹ö Á¾·ù

À¥ ÇÁ·Î±×·¡¹Ö / PHP (19, ±Û 13, ÀÚ·á 15)
ÇÁ·Î±×·¡¹Ö Åø / IDE (12, ÀÚ·á 3)
¶óÀ̺귯¸® (3)
C, C++ (10, ÀÚ·á 11)
Java(ÀÚ¹Ù) (13, ±Û 1, ÀÚ·á 5)
Python (ÆÄÀ̽ã) (5, ÀÚ·á 2)
½© ÇÁ·Î±×·¡¹Ö(shell script, ¼¿) (8, ±Û 3, ÀÚ·á 4)
¿ÀǼҽº / ÇÁ·ÎÁ§Æ® (2)
Perl (ÆÞ) (7, ÀÚ·á 3)
ÀÓº£µðµå(embedded) (8, ±Û 1, ÀÚ·á 6)
¹öÀü°ü¸® / CVS (8, ±Û 1, ÀÚ·á 3)
Æ÷Æà / ¸¶À̱׷¹ÀÌ¼Ç (1, ÀÚ·á 1)
Assembly (¾î¼Àºí¸®) (3, ÀÚ·á 1)
µð¹ö±ë, µð¹ö±×(debug), µð¹ö°Å (4, ±Û 1, ÀÚ·á 3)
XML (2)
±âŸ¾ð¾î (2, ÀÚ·á 1)
¸ð¹ÙÀÏ(mobile, wap) (2, ÀÚ·á 1)

  expect(¶Ç´Â Tcl)¿¡¼­ Á¤±ÔÇ¥Çö½ÄÀ¸·Î ¹®ÀÚ¿­ ¸ÅĪ ÀÛ¼ºÀÏ : 2009/08/05 11:46
 
  • ±Û¾´ÀÌ : ÁÁÀºÁøÈ£ ( http://coffeenix.net/ )
  • Á¶È¸¼ö : 25188
          [ ÀÌÀüÈ­¸é / ¼öÁ¤ ]   ºñ¹Ð¹øÈ£ :     Àμâ¿ë È­¸é
      Á¦  ¸ñ : expect(¶Ç´Â Tcl)¿¡¼­ Á¤±ÔÇ¥Çö½ÄÀ¸·Î ¹®ÀÚ¿­ ¸ÅĪ
    ÀÛ¼ºÀÚ : ÁÁÀºÁøÈ£(truefeel, http://coffeenix.net/ )
    ÀÛ¼ºÀÏ : 2009.8.4(È­)

    expect ½ºÅ©¸³Æ®´Â TclÀ» ÀÌ¿ëÇÑ ½ºÅ©¸³Æ® ¾ð¾î´Ù. expect¿¡¼­ È®ÀåµÈ ¸í·É¸¸ »ç¿ëÇÏÁö ¾ÊÀ¸¸é Tcl¿¡¼­µµ ±×´ë·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÀÌ ±Û¿¡¼­ »ç¿ëÇÑ ½ºÅ©¸³Æ®´Â expect³ª Tcl¿¡¼­ µ¿ÀÏÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖ´Ù.

    expect ½ºÅ©¸³Æ®³ª Tcl¿¡¼­ Á¤±Ô Ç¥Çö½ÄÀ¸·Î ¹®ÀÚ¿­À» ¸ÅĪÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ ¼³¸íÇÑ´Ù. Á¤±Ô Ç¥Çö½Ä¿¡ ´ëÇÑ ±âº» ¼³¸íÀº ÇÏÁö ¾Ê´Â´Ù. Á¤±Ô Ç¥Çö½ÄÀÌ ¹«¾ùÀ̸ç, Ç¥Çö½ÄÀº ¾î¶»°Ô µÇ´ÂÁö¿¡ ´ëÇؼ­´Â ÀüÁ¤È£´ÔÀÌ ¾²½Å 'Á¤±ÔÇ¥Çö½Ä ±âÃÊ'( http://coffeenix.net/doc/regexp/ ) ¶Ç´Â ½Å¼º±¹´ÔÀÇ 'Using Regular Expression'( http://coffeenix.net/doc/regexp/ ) ¹®¼­¸¦ Àо±â ¹Ù¶õ´Ù. ÀÌ ±ÛÀº expect(¶Ç´Â Tcl)¿¡¼­ ¸ÅĪ ÆÇ´ÜÀ» ¾î¶»°Ô ÇÏ´ÂÁö¸¦ ¸ñÀûÀ¸·Î ÇÑ´Ù.



    1. regexp ¸í·É¾î

    regexp ¸í·É¾î¸¦ »ç¿ëÇϴµ¥ ±âº» Çü½ÄÀº ´ÙÀ½°ú °°´Ù. '¹®ÀÚ¿­'³»¿¡ 'Á¤±ÔÇ¥Çö½Ä'°ú ¸ÅĪµÇ´Â °ÍÀÌ ÀÖ´Ù¸é 1ÀÌ»óÀ», ¾ø´Ù¸é 0¸¦ returnÇÑ´Ù. ±×¸®°í ¸ÅĪÀÌ µÆ´Ù¸é '¸ÅĪµÈ°á°ú_ÀúÀåÇÒ_º¯¼ö¸í' º¯¼ö¿¡ ¸ÅĪµÈ ºÎºÐÀÇ ¹®ÀÚ¿­ÀÌ ÀúÀåµÈ´Ù.

     
    Çü½Ä : regexp {Á¤±ÔÇ¥Çö½Ä} ¹®ÀÚ¿­ ¸ÅĪµÈ°á°ú_ÀúÀåÇÒ_º¯¼ö¸í
     


    ¿¹¸¦ µé¾îº¸ÀÚ. ½©»ó¿¡¼­ ¹Ù·Î Å×½ºÆ®ÇÒ °ÍÀ̹ǷΠtclsh (Tcl½©)À» ½ÇÇàÇϰųª expect¸í·ÉÀ» ½ÇÇàÇÑ´Ù.

     
    $ tclsh (tclsh ½ÇÇà. ¾Æ·¡ %´Â tcl ÇÁ·ÒÇÁÆ®)
    %
    % set str "1234abcd1234"      <-- º¯¼ö¼±¾ð
    1234abcd1234
    % regexp {1[0-9]+} $str match <-- $strº¯¼ö¿¡ Á¤±Ô½Ä°ú ¸ÅĪµÇ´Â ¹®ÀÚÀÏÀÌ ÀÖ´ÂÁö ÆÇ´Ü
    1                                    <-- ÀÖÀ¸¹Ç·Î 1À» return
    % puts $match                 <-- ¸ÅĪµÈ ¹®ÀÚ¿­ÀÌ $match¿¡ ÀúÀåµÇ¾î ÀÖÀ½À» È®ÀÎ
    1234
    % exit

    ¶Ç´Â
    $ expect (expect½ÇÇà. ¾Æ·¡ expect¼ýÀÚ> ´Â expect ÇÁ·ÒÇÁÆ®)
    expect1.1> set str "1234abcd1234"
    1234abcd1234
    expect1.2> regexp {1[0-9]+} $str match
    1
    expect1.3> puts $match
    1234
    expect1.3>
     


    regexp¿¡ ´ÙÀ½°ú °°Àº ½ºÀ§Ä¡¸¦ ÇÔ²² »ç¿ëÇϸé À¯¿ëÇÏ´Ù.

    -nocase : ´ë¼Ò¹®ÀÚ ±¸º°À» ÇÏÁö ¾Ê´Â´Ù.
    -all    : ¸ÅĪµÇ´Â °÷ÀÌ ¿©·¯±ºµ¥ ÀÏ °æ¿ì ¸ÅĪ °¹¼ö¸¦ ¹ÝȯÇÑ´Ù.

    regexp         {1[A-Z]+} $str match ´Â 0À» ¹ÝȯÇÏ°ÚÁö¸¸,
    regexp -nocase {1[0-9]+} $str match ´Â ´ë¼Ò¹®ÀÚ ±¸º°À» ÇÏÁö ¾ÊÀ¸¹Ç·Î 1À» ¹ÝȯÇÑ´Ù.
    regexp -all    {1[0-9]+} $str match ´Â 1234abcd1234¿¡¼­ ¸ÅĪµÇ´Â °÷ÀÌ 2°÷À̹ǷΠ2¸¦ ¹ÝȯÇÑ´Ù.

    ´ÙÀ½ ¿¹Á¦´Â ¸ÅĪº¯¼ö°¡ ¿©·¯°³ »ç¿ëµÇ¾î ÀÖ´Ù.
     
    set str "12345abcd67890"
    regexp {([0-9]*)([a-z]*)([0-9]*)} $str match sub1 sub2 sub3

    puts $match
    puts $sub1
    puts $sub2
    puts $sub3
     


    Á¤±ÔÇ¥Çö½Ä¿¡ Àͼ÷ÇÑ ºÐÀ̶ó¸é ±Ý¹æ ´«Ä¡Ã«À» °ÍÀÌ´Ù. $match´Â ¸ÅĪµÈ ¹®ÀÚ¿­ Àüü°¡, µÚ¿¡ $sub1~$sub3±îÁö 3°³ÀÇ ¼­ºê¸ÅĪº¯¼ö´Â ¾ÕÂÊ ( )ºÎÅÍ Çϳª¾¿ ¸ÅĪµÇ¾î ÀúÀåµÈ´Ù.

     
    # °á°ú°ª
    12345abcd67890
    12345
    abcd
    67890
     


    2. ½ºÅ©¸³Æ® ¿¹Á¦

    ÁÖ¾îÁø IP Çü½ÄÀÌ ¸Â´ÂÁö °Ë»çÇÏ¿© ¸ÂÀ¸¸é IP¸¦ Ãâ·ÂÇÑ´Ù. ´Ü IPÁÖ¼Ò´Â ÀÚ¸®¼ö¸¸ ¸Â´ÂÁö üũÇÏ´Â °£´ÜÇÑ ¸ÅĪ ¹æ½ÄÀ» »ç¿ëÇß´Ù.

     
    #!/usr/bin/expect --
    #

    # IP address
    set ip(1) "192.168.123.1"
    set ip(2) "coffeenix@"
    set ip(3) "1234.1234.1234.1234"
    set ip(4) "127.0.0.1"
    set ip_cnt  [array size ip]

    for { set num 1 } { $num <= $ip_cnt } { incr num } {
    ¡¡¡¡¡¡set result [regexp {([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})} $ip($num) match]
    ¡¡¡¡¡¡puts "$num => ¸ÅĪ ¿©ºÎ : $result (1ÀÌ¸é ¸ÅĪµÊ)"

    ¡¡¡¡¡¡if { $result } {
    ¡¡¡¡¡¡¡¡¡¡¡¡puts "     ¸ÅĪ IP   : $match"
    ¡¡¡¡¡¡}
    }


    # ½ÇÇà °á°ú
    1 => ¸ÅĪ ¿©ºÎ : 1 (1ÀÌ¸é ¸ÅĪµÊ)
         ¸ÅĪ IP   : 192.168.123.1
    2 => ¸ÅĪ ¿©ºÎ : 0 (1ÀÌ¸é ¸ÅĪµÊ)
    3 => ¸ÅĪ ¿©ºÎ : 0 (1ÀÌ¸é ¸ÅĪµÊ)
    4 => ¸ÅĪ ¿©ºÎ : 1 (1ÀÌ¸é ¸ÅĪµÊ)
         ¸ÅĪ IP   : 127.0.0.1
     


    3. Âü°í ¹× °ü·Ã ÀÚ·á

    1) New Regular Expression Features in Tcl 8.1
       http://www.tcl.tk/doc/howto/regexp81.tml

    2) regexp
       http://tmml.sourceforge.net/doc/tcl/regexp.html

    3) Regular Expression Examples
       http://wiki.tcl.tk/989

    4) expect ¿¹Á¦µé
       - ¿©·¯ ¼­¹ö¿¡ ÀÏ°ý ¸í·ÉÀ» À§ÇÑ expect ½ºÅ©¸³Æ®
         http://coffeenix.net/board_view.php?bd_code=1519 (2007)
       - ½ºÀ§Ä¡Àåºñ Á¢¼Ó/¸í·É¿ë expect ½ºÅ©¸³Æ®
         http://coffeenix.net/board_view.php?bd_code=1327 (2006.1)
       - expect ÇÁ·Î±×·¡¹Ö ¿¹ µÎ¹ø°
         http://coffeenix.net/board_view.php?bd_code=115
       - expect ÇÁ·Î±×·¡¹Ö ¿¹
         http://coffeenix.net/board_view.php?bd_code=112
      Ä¿ÇǴнº Ä«Æä ÃÖ±Ù ±Û
    [12/25] Àνº&#5
    [10/20] Cross Compiler ±ò
    [07/14] SSL ¬¡¬°
    [04/26] Re: µµ½ºÈ­¸é ¿ø°ÝÁ¶Á¾ ¿©ºÎ
    [04/25] µµ½ºÈ­¸é ¿ø°ÝÁ¶Á¾ ¿©ºÎ
    [10/30] Cshell¿¡¼­ ³­¼ö ¼³Á¤
    [10/23] °øÇ×öµµÁÖ½Äȸ»ç SE ±¸ÀÎ Ëì
    [01/26] Re: wgetÀ¸·Î ´Ù¸¥¼­¹ö¿¡ÀÖ´Â µð·ºÅ丮¸¦ °¡Á®¿À·Á°íÇÕ´Ï´Ù.
    [01/25] wgetÀ¸·Î ´Ù¸¥¼­¹ö¿¡ÀÖ´Â µð·ºÅ丮¸¦ °¡Á®¿À·Á°íÇÕ´Ï´Ù.
    [01/11] ƯÁ¤ ¾Èµå·ÎÀ̵å WebView ¹öÀü¿¡¼­ SSL ¹®Á¦ (WebView ¹ö±×)
    [08/01] DNS forwarder (Àü´ÞÀÚ) ¼­¹ö¸¦ ÅëÇؼ­ Äõ¸®ÇÏ¸é ¿ª¹æÇâÀ» ¹Þ¾Æ¿ÀÁú ¸øÇÕ´Ï´Ù.
    [05/16] (ÁÖ)ÈÄÀÌÁî ½Ã½ºÅÛ¿£Áö´Ï¾î (°æ·ÂÀÚ) ¸ðÁý
    [02/15] [AWS] Cloudfront edge È®ÀÎÇϱâ
    [01/20] Mobile Service/eCommerce ±â¾÷¿¡¼­ Server / Java / PHP °³¹ßÀÚ ±¸ÀÎ
    [01/11] źźÇÑ ÆÛºí¸®½Ì ¸ð¹ÙÀϱâ¾÷¿¡¼­ Mobile °³¹ßÀÚ¸¦ ¸ð½Ê´Ï´Ù.
      New!   ÃÖ±Ù¿¡ µî·ÏÇÑ ÆäÀÌÁö
      KiCad EDA Suite project (Free/Libre/Open-Source EDA Suite) (CAD)
      ¿ÀÇÂij½ºÄÉÀ̵å ijµå (OpenCASCADE CAD)
      QCad for Windows --- GNU GPL (Free Software)
      The Hello World Collection
      IPMI¸¦ È°¿ëÇÑ ¸®´ª½º ¼­¹ö°ü¸®
      DNS ¼³Á¤ °Ë»ç
      nagiosgraph ¼³Ä¡ ¹æ¹ý
      Slony-I ¼³Ä¡ ¹æ¹ý (postgresql replication tool)
      Qmail±â¹ÝÀÇ Anti spam ½Ã½ºÅÛ ±¸ÃàÇϱâ
      clusterssh

    [ ÇÔ²²ÇÏ´Â »çÀÌÆ® ]




    ¿î¿µÁø : ÁÁÀºÁøÈ£(truefeel), ¾ß¼ö(yasu), ¹ü³ÃÀÌ, sCag
    2003³â 8¿ù 4ÀÏ~