4-2 �q�Φ����򥻥Ϊk

§Ú­Ì¥i¥H¨Ï¥Î regexp «ü¥O¤ñ¹ï¦r¦ê¡A¤]´N¬O§ä¥X¬Y¤@­Ó¯S©w«¬ºAªº¦r¦ê¦b¥t¤@­Ó¦r¦êªº¥X²{¦ì¸m¡A³o¬O³q¥Î¦¡ªº³Ì°ò¥»¥Îªk¡C¨Ò¦p¡A¦pªG­n§ä¥X¡ulove¡v¦b¤@­Ó¦r¦ê¡uLove me tender, love me sweet, never let me go¡v¥X²{ªº¦ì¸m¡A¥i¥Î¤U¦Cµ{¦¡½X¡G

Example 1: 04-³q¥Î¹Bºâ¦¡/regExp01.mstring = 'Love me tender, love me sweet, never let me go'; pattern = 'love'; startIndex = regexp(string, pattern)startIndex = 17

¦¹¦^¶Çµ²ªG¥Nªí¡ulove¡v¦b string ÅܼƩҥX²{ªº¦ì¸m¬O 17¡C¡]½Ðª`·N¡A¤j¤p¼g¦³§O¡I¡^

­Y­n¶i¦æ¡u¤j¤p¼g§¡¥i¡v¡]Ignore Cases¡^ªº¤ñ¹ï¡A«h¥i¥H¨Ï¥Î regexpi «ü¥O¡A¨Ò¦p¡G

Example 2: 04-³q¥Î¹Bºâ¦¡/regExp02.mstring = 'Love me tender, love me sweet, never let me go'; pattern = 'love'; startIndex = regexpi(string, pattern)startIndex = 1 17

¦¹¦^¶Çµ²ªG¥Nªí¡uLove¡v©M¡ulove¡v¦b string ÅܼƩҥX²{ªº¦ì¸m¤À§O¬O 1 ©M 17¡C

Hint
¥»³¹©Ò¦³¨Ï¥Î regexp ªº½d¨Ò¡A§¡¥i¥H¥N´«¦¨ regexpi¡A¥H¶i¦æ¡u¤j¤p¼g§¡¥i¡vªº¤ñ¹ï¡C

­Y­n§ä¥X¦r¦ê¥X²{ªº¶}©l©Mµ²§ô¦ì¸m¡A¥i¥H¦b¨Ï¥Î regexp ®É¡A¦h¥[¤@­Ó¿é¥XÅܼơA¨Ò¦p¡G

Example 3: 04-³q¥Î¹Bºâ¦¡/regExp03.mstring = 'Love me tender, love me sweet, never let me go'; pattern = 'me'; [start, finish] = regexp(string, pattern)start = 6 22 42 finish = 7 23 43

¨ä¤¤ start ©M finish ¥Nªí©Ò¤ñ¹ï¨ìªº¤T­Ó¡ume¡vªº¶}©l©Mµ²§ô¦ì¸m¡C

¦b¤W­z´X­Ó½d¨Ò¤¤¡Apattern ÅܼƳ£¬O¥Ñ¤@¯ë¦r¤¸©Òºc¦¨¡A©Ò¥H¨ä¥\¯à©M findstr «ü¥O¥\¯àÃþ¦ü¡A¦]¦¹µLªkÅã²{³q¥Î¹Bºâ¦¡ªº¯«©_¥\®Ä¡C¦b¥H¤U¦U¸`ªº»¡©ú¡A§Ú­Ì¦b pattern ÅܼƤ¤¥[¤J¶W¦r¤¸¡]Metacharacters¡^¡A´N¥i¥H¬Ý¥X³q¥Î¦¡ªº¯«³q¼s¤j¡C


MATLABµ{¦¡³]­p¡G¶i¶¥½g