�� 10 ���@�~

¿ï¾ÜÃD


²µªÃD

  1. ½Ð¼g¤@­Ó³q¥Î¦¡¨Ó¶i¦æ¨­¥÷ÃÒ¦r¸¹ªºÂ²©ö¤ñ¹ï¡C¡]°²³]¨­¥÷ÃÒ¦r¸¹¬O¥Ñ¤@­Ó­^¤å¦r¥À¥[¤W¤E­Ó¼Æ¦r©Ò²Õ¦¨¡C¡^
  2. ½Ð¼g¤@­Ó³q¥Î¦¡¨Ó¶i¦æ«H¥Î¥d¥d¸¹ªºÂ²©ö¤ñ¹ï¡C¡]°²³]«H¥Î¥d¥d¸¹ªº®æ¦¡¬O xxxx-xxxx-xxxx-xxxx¡A¨ä¤¤¨C¤@­Ó x ³£¬O¥Nªí¤@­Ó¼Æ¦r¡C¡^
  3. µ¹©w¤@­Ó¦r¦êÅÜ¼Æ x = " ª÷ ¡@¡@«°¡@ ªZ "¡A½Ð»¡©ú¦p¦ó¨Ï¥Î³q¥Î¦¡¨Ó§R°£¦¹¦r¦ê¤¤ªºªÅ¥Õ¡]¥]§t¥þ§ÎªÅ¥Õ¡B¥b§ÎªÅ¥Õ¡B©w¦ìÁäµ¥¡^¡C
  4. ½Ð»¡©ú¦p¦ó±N³q¥Î¦¡±Ä¥Îªº¡u³g¤ß¤ñ¹ï¡v§ï¦¨¡u³Ì¤p¤ñ¹ï¡v¡C
  5. ½Ð»¡©ú³q¥Î¦¡©Ò±Ä¥Îªº¡u¶V¥ª¶V³g¡vªº¾÷¨î¬°¦ó¡H½ÐÁ|¹ê¨Ò¨Ó»¡©ú¡C
  6. ½Ð»¡©ú¤U¦C³q¥Î¦¡ªº²[¸q¡G
    1. /^xy/
    2. /xy$/
    3. /[13579]/
    4. /[0-9]/
    5. /[a-z0-9]/
    6. /[a-zA-Z0-9]/
    7. /b[aeiou]t/
    8. /[^0-9]/
    9. /[^aeiouAEIOU]/
    10. /a.b/
    11. /a.*b/
    12. /a.*?b/
    13. /[^\^]/
    14. /^.+@.+\..{2,3}$/

µ{¦¡ÃD

½ÐºÉ¶q¨Ï¥Î¥»³¹©Ò¾Ç¨ìªº³q¥Îªí¥Üªk¨Ó§¹¦¨¤U¦C§@·~¡G
  1. (*) ¤¹³\¨­¥÷ÃÒ¦r¸¹²Ä¤@­Ó¦r¥À¤j¤p¼g§¡¥i: ½Ð­×§ï½d¨Ò regExpId01.htm¡A²£¥Í·sºô­¶¡AÅý¨Ï¥ÎªÌ¿é¤Jªº¨­¥÷ÃÒ¦r¸¹ªº²Ä¤@­Ó­^¤å¦r¥À¤£­­¤j¼g©Î¤p¼g¡C
  2. (*) ¹ï­^¤å©m¦W¶i¦æ­×¥¿: ½Ð­×§ï½d¨Ò regExpEnglishName01.htm¡A²£¥Í·sºô­¶¡AÅý¨Ï¥ÎªÌ¦bÅçÃÒ¸ê®Æ®É¡Aµ{¦¡½X·|¥ý¹ï­^¤å¦W¦r¶i¦æ­×¥¿¡G§â¨C­Ó¦r·Jªº²Ä¤@­Ó¦r¥À§ï¦¨¤j¼g¡A¨ä¾l¤p¼g¡C
  3. (*) ¶Ã¼Æ²£¥Í¨­¥÷ÃÒ¦r¸¹: ½Ð®Ú¾Ú¨­¥÷ÃÒ¸¹½Xªº½s½X³W«h¡A§Q¥Î¶Ã¼Æ¡A¤@¦¸²£¥Í¤­²Õ¦³®Äªº¨­¥÷ÃÒ¸¹½X¡A½d¨Òªí³æ¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]generateIdNumber01.htm¡^¡G

    ½Ðª`·N¡G

    • ¿é¤Jªº­^¤å¦r¥À¥²¶·¬O¦X®æªº¡C
    • ¥²¶·±N­^¤å¦r¥ÀÂন¤j¼g¡A¦A¥[¤W¤E¦ì¼Æ¦r¡C
    • ¥²¶·§Q¥Î¶Ã¼Æ²£¥Í¡A©Ò¥H¨C¦¸²£¥Íªº¤­²Õ¸¹½X³£À³¸Ó¤£¤@¼Ë¡C
  4. (*) ¶Ã¼Æ²£¥Í«H¥Î¥d¥d¸¹: ½Ð®Ú¾Ú«H¥Î¥d¸¹½Xªº½s½X³W«h¡A§Q¥Î¶Ã¼Æ¡A¤@¦¸²£¥Í¤­²Õ¦³®Äªº«H¥Î¥d¸¹½X¡A½d¨Òªí³æ¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]generateCreditCardNumber01.htm¡^¡G

  5. (**) ¨­¥÷ÃÒ¦r¸¹ÅçÃÒ: ¹ï¨Ï¥ÎªÌ¿é¤Jªº¨­¥÷ÃÒ¦r¸¹¶i¦æ°ò¥»ÅçÃÒ¡G½Ð§A¥²¶·³]­p¤@­Óºô­¶¡A¥]§t¤@­Ó¤å¦rÄæ¦ì¡A¯àÅý¨Ï¥ÎªÌ¿é¤J­Ó¤Hªº¨­¥÷ÃÒ¦r¸¹¡A¨Ã¦b«ö¤U¡uÅçÃÒ¡v¶s«á¡AÅçÃÒ¦¹¿é¤J¸ê®Æ¡C­Y¿é¤J¸ê®Æº¡¨¬¨­¥÷ÃÒ¦r¸¹ªº½s½X³W«h¡A«h¥Hĵ§iµøµ¡Åã¥Ü¡u³q¹L¡v¡A§_«hÅã¥Ü¡u¤£³q¹L¡v¡C¡]¨­¥÷ÃÒ¦r¸¹ªº²Ä¤@­Ó¦r¥À¡A¥i¥H¤¹³\¬O¤j¼g©Î¤p¼g¡C¡^½d¨Òªí³æ¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]regExpId03.htm¡^¡G

  6. (**) «H¥Î¥d¥d¸¹ÅçÃÒ: ¹ï¨Ï¥ÎªÌ¿é¤Jªº«H¥Î¥d¥d¸¹¶i¦æ°ò¥»ÅçÃÒ¡G½Ð§A¥²¶·³]­p¤@­Óºô­¶¡A¥]§t¤@­Ó¤U©Ô¦¡¿ï³æ¡A¥i¥HÅý¨Ï¥ÎªÌ¶ñ¤J«H¥Î¥dÃþ§O¡]Visa¡BMaster¡BAmerican Express¡^¡A¥H¤Î¤@­Ó¤å¦rÄæ¦ì¡A¯àÅý¨Ï¥ÎªÌ¿é¤J­Ó¤Hªº«H¥Î¥d¥d¸¹¡A¨Ã¦b«ö¤U¡uÅçÃÒ¡v¶s«á¡AÅçÃÒ¦¹¿é¤J¸ê®Æ¡C­Y¿é¤J¸ê®Æº¡¨¬«H¥Î¥d¥d¸¹ªº½s½X³W«h¡A«h¥Hĵ§iµøµ¡Åã¥Ü¡u³q¹L¡v¡A§_«hÅã¥Ü¡u¤£³q¹L¡v¡C½d¨Òªí³æ¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]regExpCreditCardNumber02.htm¡^¡G

  7. (***) ¹q¤l¶l¥óÅçÃÒ: §óºë·Çªº¹q¤l¶l¥ó³q¥Î¦¡¡G¦b½d¨Ò regExpEmail01.htm ¤¤¡A§Ú­Ì¨Ï¥Î¤@­Ó²³æªº³q¥Î¦¡¡u/^.+@.+\..{2,3}$/¡v¨Ó¥Nªí¹q¤l¶l¥óªº®æ¦¡¡C¦ý¬O¨Æ¹ê¤W¡A¦¹³q¥Î¦¡¨Ã¤£§¹¥þºë·Ç¡A½Ð§A³]­p¤@­Óºô­¶ regExpEmail02.htm¡A¨Ï¥Î¸û½ÆÂøªº³q¥Î¦¡¡A¥i¥H§óºë·Ç¦aªí¥Ü¤@¯ë¹q¤l¶l¥óªº®æ¦¡¡Aºô­¶®æ¦¡¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]regExpEmail02.htm¡^¡G

    ½Ð°È¥²»¡©ú§Aªº³q¥Î¦¡¦p¦ó¯àºë·Ç¦a´y­z¹q¤l¶l¥óªº®æ¦¡¡C

  8. (***) HTTPºô§}ÅçÃÒ: ½Ð³]­p¤@­Óºô­¶¡A¯à°÷ºë½T¦a´y­z¤@­Ó¥H¡uhttp://¡v¶}©lªº­Ó¤Hºô§}¡A°ò¥»­n¨D¦p¤U¡G
    • ¦X®æºô§}½d¨Ò¡Ghttp://www.cs.nthu.edu.tw/~jang", "http://www.mathworks.com", "http://www.cs.nthu.edu.tw:4500/~jang/publie/index.asp"
    • ¤£¦X®æºô§}½d¨Ò¡G"www.mathworks.com", "http://www..com"
    ºô­¶®æ¦¡¦p¤U¡G

    ²ßÃD®æ¦¡½d¥»¡]regExpHttp01.htm¡^¡G

    ½Ð°È¥²»¡©ú§Aªº³q¥Î¦¡¦p¦ó¯àºë·Ç¦a´y­z http ªººô§}®æ¦¡¡C

  9. (**) ¹ïªí³æ¸ê®Æ¶i¦æ­×¥¿¤ÎÅçÃÒ: ½Ð¥Î³q¥Îªí¥Üªk¨Ó¹ï¤U¦Cªí³æ¸ê®Æ¶i¦æ­×¥¿¤ÎÅçÃÒ¡G

    • ­^¤å¦W¦r¡G
      ®æ¦¡»Ý¨D¡G³Ì¤Ö¨â­Ó¡B³Ì¦h¤T­Ó­^¤å¦r¡A¨C­Ó­^¤å¦rªº²Ä¤@­Ó¦r¥À¥²¶·§ï¦¨¤j¼g¡A¨ä¾l¤p¼g¡A¨Ã½Ð¥h°£¤£¥²­n¤§ªÅ¥Õ¡C

    • ¤¤¤å¦W¦r¡G
      ®æ¦¡»Ý¨D¡G³Ì¤Ö¨â­Ó¡B³Ì¦h¥|­Ó¤¤¤å¦r¡A¨Ã½Ð¥h°£¤£¥²­n¤§ªÅ¥Õ¡]§t¤j¤­½XªºªÅ¥Õ¡^¡C

    • ©Ê§O¡G¨k ¤k
      ®æ¦¡»Ý¨D¡G¦Ü¤Ö¿ï¤@­Ó

    • ­Ó¤H±K½X¡G
      ®æ¦¡»Ý¨D¡G5 ¦Ü 8 ­Ó­^¤å¦r¥À©Î¼Æ¦r¡A¦ý¤£¯à¥þ¬O­^¤å¦r¥À©Î¥þ¬O¼Æ¦r
  10. (***) ©â¨úºô­¶¤¤ªº³sµ²: ¦b¦¹§@·~¤¤¡A§Ú­Ì±N½m²ß¨Ï¥Î³q¥Îªí¥Üªk¨Ó©â¨úºô­¶¤¤ªº³sµ²¡]¥]§t¤å¦r»Pºô§}¡^¡C¬°¤F¨ú±oºô­¶ªº¤º®e¡A§Ú­Ì¥²¶·§ï¥Î WSH (Window Scripting Host) ¨Ó¶i¦æ¦¹§@·~¡A¤@­Ó²³æªº WSH ½d¨Òµ{¦¡¦p¤U¡G

    ­ì©lÀÉ¡]titleExtract.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
    // Request a homepage and extract its title by regular expression
    // Roger Jang, 20081115
    url = "http://mirlab.org/jang/courses/webProgramming/homework/linkExtraction/testPage4linkExtraction.htm";
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.open("GET", url, false, "");
    xmlHttp.send();				// Send the request
    contents = xmlHttp.responseText;	// Get the contents
    //WScript.Echo(contents);		// Print the contents if necessary
    
    // Use regular expression to extract the title
    re = new RegExp("<title>(.*?)<\/title>", "gi");;
    index=contents.search(re);
    WScript.Echo("index = " + index);
    WScript.Echo("title = " + RegExp.$1);

    ­Y­n°õ¦æ¦¹½d¨Ò¡A½Ð¤U¸ü¦¹½d¨Ò«á¡A¦b DOS µøµ¡¿é¤J

    cscript titleExtract.js °²³]ºô¸ôºZ³q¡A«h¦¹®É¦bµøµ¡©ÒÅã¥Üªºµ²ªG¦p¤U¡G Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. index = 14 title = Web Programming (CS3431): Test page for link extraction ¥Ñ¦¹¥i¨£¦¹½d¨Ò¥i¥H¥¿½T¦a©â¥X©Òµ¹ºô­¶ªº¼ÐÃD¡C½Ðª`·N¡AWSH Àɮתº°ÆÀɦW¬O js¡A¥Nªí©Ò¥Îªºµ{¦¡»y¨¥¬O JavaScript¡A©Ò¥H¥»¸`©Ò±Ðªº³q¥Îªí¥Üªk³£¥i¥H¨Ï¥Î¡C°ß¤@ªº¤p®t§O¬O¡G­Y­n¦L¥X¦r¦ê¡A¦b WSH ¥²¶·¨Ï¥Î WScript.Echo("...")¡C

    §Aªº¥ô°È¡A´N¬O§ï¼g¦¹ÀɮסA¨Ï¨ä¯à¨Ï¥Î³q¥Îªí¥Üªk¨Ó§ì¥X¬Y¤@­Óºô­¶ªº³sµ²¡A¥]§t³sµ²ªº¤å¦r»P³sµ²ªººô§}¡C½Ðª`·N¡A§Aªºµ{¦¡½Xªº¥\¯à¥i¥H¥Ñ²L¤J²`¡A¹F¨ì¤U­z¤T¶µ¥\¯à¡G

    1. ¯à°÷¥¿½T¦a©â¨úÃþ¦ü¤U¦Cªº³sµ²¡G
      • It's me <A Href =/jang>It's <b>me</b></a>
      • This is Google <a HREF = "http://www.google.com">This is <u>Google</u></a>
    2. ¤¶©ó <xmp> »P </xmp> ¤§¶¡ªº³sµ²¡A¤£À³¸Ó³Q©â¨ú¡C
    3. ¯à°÷¤À¿ë¦Pºô°ì (Same-domain) ªº³sµ²©M²§ºô°ì (Different-domain)ªº³sµ²¡C

    ­Y¥H¥»§@·~ºô­¶¬°¨Ò¡A©Ò²£¥Íªº¿é¥XÀ³¸ÓÃþ¦ü¤U­zµ²ªG¡G

    Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. regExpId01.htm ===> example/regExpId01.htm ===> Same domain regExpEnglishName01.htm ===> example/regExpEnglishName01.htm ===> Same domain generateIdNumber01.htm ===> exerciseTemplate/generateIdNumber01.htm ===> Same domain ... titleExtract.js ===> example/titleExtract.js ===> Same domain ©Òµ¹ºô­¶ ===> http://mirlab.org/jang/courses/webProgramming/homework/linkExtraction/testPage4linkExtraction.htm ===> Same domain It's me ===> /jang ===> Same domain This is Google ===> http://www.google.com ===> Different domain JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó¥Î¤áºÝ ===> /jang/books/javaScript ===> Same domain ¡]½Ð¸Õ¬Ý¬Ý§U±Ð©Òµ¹ªº´ú¸Õºô­¶¡C¡^

JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©óºô­¶¥Î¤áºÝ