ãã®éšåã§ã¯ãæ£èŠè¡šçŸãšã³ãžã³ã®ä»çµã¿ãæ£èŠè¡šçŸãéåžžã«é ããšèãã人ããªãå€ãã®ãšã³ãžã³ã®äœæè ãPOSIXæšæºã«åŸã£ãŠããªãã®ãã«ã€ããŠã話ããããšæããŸãã
å€ãã®ã¿ã¹ã¯ãšåæ§ã«ããæ£èŠè¡šçŸã®æååã§äžèŽãèŠã€ããããšããåé¡ã解決ããããã®å€ãã®ã¢ãããŒããšååããããŸãã ãã®å Žåã®åºæ¬ååã¯ã2ïŒæ£èŠè¡šçŸã«ãã£ãŠå¶åŸ¡ãããäžèŽããæ€çŽ¢ãšãæååã«ãã£ãŠé§åãããäžèŽããæ€çŽ¢ã§ãã ãããã®åååã®æå³ã詳ããèŠãŠã¿ãŸãããã
ã¹ããªã³ã°é§ååãããã³ã°
ãã®ã¿ã€ãã®æ£èŠè¡šçŸãšã³ãžã³ã¯ãããããDFAïŒ æ±ºå®æ§æéç¶æ ãã·ã³ ïŒã䜿çšããŠå®è£ ãããŸãã äž»ãªå©ç¹ã¯ãïŒå¥ã®ååãšæ¯èŒããŠïŒäžèŽãèŠã€ããã®ã«éåžžã«éãããšã§ãã åœç¶ããã®ååã«ã¯å€ãã®æ¬ ç¹ããããŸãïŒããã§ãªããã°ãé¢çœããªãã§ãããïŒïŒã
第äžã«ãã³ã³ãã€ã«æéïŒããã°ã©ã ã®ãœãŒã¹ã³ãŒããã³ã³ãã€ã«ããã®ã§ã¯ãªããæ£èŠè¡šçŸããšã³ãžã³ã®å éšæ§é ã«ã³ã³ãã€ã«ããããšãæå³ããŸãïŒã¯éåžžã«é·ãå ŽåããããŸãïŒå¥ã®ååãšæ¯èŒããŠïŒã å®éãã³ã³ãã€ã«äžã«ãç¹å®ã®ãã¿ãŒã³ãæ¯èŒããããã®ããã°ã©ã å šäœãäœæãããŸãã DFAã¯æååã«ãã£ãŠãå¶åŸ¡ããããŠãããã³ã³ãã€ã«æã«æååãããããªããããèãããããã¹ãŠã®æååãèæ ®ããŠã¢ã«ãŽãªãºã ãäœæãããŸãã è€éãªåŒã®å Žåãããã¯æããã«ããã»ã©é«éã§ã¯ãããŸããã
第äºã«ãDKAã¯ãæ£èŠè¡šçŸã§æ £ããŠãã䟿å©ã§å¿ èŠãªæ©èœã®å€ãããµããŒãããŠããŸããã ããšãã°ãä¿æãã©ã±ããã¯ãµããŒããããŠããŸããã ãã¡ãããDKAã§å©çšå¯èœãªã»ããã§ã¯ãå€ããå°ãªããå®éã®ç¶æ³ã§è¡ãããšã¯äžå¯èœã§ãã ãããã£ãŠãDKAã¯çŽç²ãªåœ¢ã§ã¯ã»ãšãã©ã©ãã§ã䜿çšãããŠããŸããã ããããããããããã€ããªããããšã³ãžã³ã§ããŸã䜿çšãããŠããŸããæãåçŽãªå Žåãç¹å®ã®æ£èŠè¡šçŸã«æãé©ãããšã³ãžã³ãéžæããŸãã
ãããã£ãŠã倧éã®ããã¹ããæ€çŽ¢ããå¿ èŠããããšåæã«ãæ£èŠè¡šçŸãããã»ã©è€éã§ãªãå ŽåãDKAãããåªãããã®ãèŠã€ããããšã¯å°é£ã§ãã
ããã§ã¯ãDKAã¯ã©ã®ããã«æ©èœããŸããïŒ ãã®ãšã³ãžã³ã¯ããã®ããã«æ©èœããããããã©ã€ã³é§åããšåŒã°ããŸãã ã¹ããŒããã·ã³ã¯ãäžèŽãæ€åºããè¡ãèªã¿åãããã®è¡ããã¿ãŒã³ãšæ¯èŒããŸãã æéããšã«ãã¢ã«ãŽãªãºã ã¯ãã¿ãŒã³ãšæååã®ã©ã®éšåãäžèŽãããããèªèãããŸãã ã¢ã«ãŽãªãºã ãè¡å šäœãå®å šã«ã¹ãã£ã³ãããšãè¡ã®å é ã«è¿ãæé·äžèŽã®ã¿ãéžæãããããåçãšããŠæ®ããŸãã
æ確ã«ããããã«ãæ£èŠè¡šçŸ
^abc\w+e$
ãš2è¡
abcde
ãš
abce
ããããšä»®å®ããŸãã åŒãæåã®è¡ãšäžèŽããããšã¯æããã§ããã2çªç®ã®è¡ãšã¯äžèŽããŸããã
DKAã¡ã«ããºã ã§äžèŽã®æ€çŽ¢ãã©ã®ããã«çºçããããèããŠã¿ãŸãããã æåã®è¡ã«ã¯æ¬¡ã®ã·ãŒã±ã³ã¹ããããŸãã
- æååãaãã®æåã®æå-ã¡ã¿æå
^
ãšäœçœ®ãäžèŽããŸãã 1ã€ã®éšåäžèŽãèŠã€ãããŸããã - æååãaãã®æåã®æå-ãã¿ãŒã³ã®2çªç®ã®æåã®å€ãšäžèŽããŸãã ã¢ã«ãŽãªãºã ã¯åŒãç¶ã1ã€ã®éšåäžèŽãå°ããŸãã
- æååãbãã®2çªç®ã®æå-å€ããã¿ãŒã³ã®3çªç®ã®æåãšäžèŽããŸãã ã¢ã«ãŽãªãºã ã¯åŒãç¶ã1ã€ã®éšåäžèŽãå°ããŸãã
- æååãcãã®3çªç®ã®æå-ãã¿ãŒã³ã®4çªç®ã®æåãšå€ãäžèŽããŸãã ã¢ã«ãŽãªãºã ã¯åŒãç¶ã1ã€ã®éšåäžèŽãå°ããŸãã
- æååãdãã®4çªç®ã®æå-ãã¿ãŒã³ã®5çªç®ã®ã¡ã¿æå
\w
å€ãšäžèŽããŸãã æ°éè©ã§ã¯ãã¡ã¿æåã®äžèŽãå°ãªããšã1åçºçããå¿ èŠããããŸãã æ¡ä»¶ãæºããããŸãã ã¢ã«ãŽãªãºã ã¯åŒãç¶ã1ã€ã®éšåäžèŽãå°ããŸãã - æååãeãã®5çªç®ã®æå-ãã¿ãŒã³ã®8çªç®ã®æåãšå€ãäžèŽããŸãã åã®ã¡ã¿æåã®éæå®åæ¡ä»¶ãæºãããããeãèšå·ããã¿ãŒã³ã®8çªç®ã®æåãšã®äžèŽãšããŠããŸãã¯
\w
ã¡ã¿æåãšã®äžèŽãšããŠã«ãŠã³ãã§ããŸãã ã¢ã«ãŽãªãºã ã¯ãããšããã®äž¡æ¹ãè¡ãã2ã€ã®éšåäžèŽããªãŒããç¶ããŸãã ãã®ç¹ãå¿ããªãã§ãã ãããå¥ã®ååã§ã¯ãéåžžã«å€§ããªéãããããŸãã - è¡ã®6çªç®ã®æåãæ¬ èœããŠããŸã-
$
ã¡ã¿æåãšäœçœ®ãäžèŽããŠããŸãã å®å šãªäžèŽã1ã€èŠã€ãããŸãããã2çªç®ã®éšåäžèŽã¯æåŸ ã©ããã§ã¯ãªããç Žæ£ãããŸãã - è¡ãçµãã£ãã®ã§ãçµæãè¿ããŸãã
2çªç®ã®ã±ãŒã¹ã§äœãèµ·ãããïŒ
- ã¢ã«ãŽãªãºã ã®éå§ã¯ãŸã£ããåãã§ãããã«æååãeãã®4çªç®ã®æåã«ç§»åããŸã
- æååãeãã®4çªç®ã®æåã®å€ã¯ããã¿ãŒã³
\w
5çªç®ã®ã¡ã¿æåãšäžèŽããŸãã éæå®åæ¡ä»¶ã§ã¯ã1ã€ã®æåã«å¯ŸããŠå°ãªããšã1ã€ã®äžèŽãååšããå¿ èŠããããŸãã ãããã£ãŠããeãã¯\w
ã¡ã¿æåã«ãã£ãŠãã£ããã£ãããŸãã 1éšåäžèŽã - è¡ã®5çªç®ã®æåãæ¬ èœããŠããŸã-ãeãæåãšäžèŽãããã¿ãŒã³ã¯ãããŸããã æããã«ãæååã¯äžèŽããŸããã
- è¡ãçµäºããäžèŽãããã®ã¯ãããŸãããçµæãè¿ããŸãã
ãããã®2ã€ã®äŸã§äœãããããŸããïŒ ã¢ã«ãŽãªãºã ã¯ãäžèŽãããã©ããã¯é¢ä¿ãããŸããã æåããšã«1è¡ãã€ã¹ãã£ã³ãããã¿ãŒã³ã«åºã¥ããŠäžèŽãç §åããŸãã äœæ¥ã®æåŸã«ããã€ãã®å®å šãªäžèŽãããå Žåãçµæã¯ãè¡ã®å·Šç«¯ã«æãè¿ããæãé·ããã®ã«ãªããŸãã
å®éãã¢ã«ãŽãªãºã ãéåžžã«é«éã«æ©èœããçç±ãæããã«ãªããŸãã å Žåãé€ããŠãæååã®åæåã¯1åã ã衚瀺ãããŸãã ãŸãããã¿ãŒã³ã®ã³ã³ãã€ã«ã«æéããããçç±ãæããã«ãªããŸããè€éãªãã¿ãŒã³ã®å ŽåãéšåäžèŽãæ£ããå®è¡ããã«ã¯ãå€ãã®æ¡ä»¶ãšäŸåé¢ä¿ãèæ ®ããå¿ èŠããããŸãã
çŸæç¹ã§ã¯ãDKAãšã³ãžã³ã¯grepãŠãŒãã£ãªãã£ã§ãšã³ãžã³éžæã¡ã«ããºã ã®äžéšãšããŠäœ¿çšãããTclèšèªã§ã¯ãã€ããªãããšã³ãžã³ã®äžéšãšããŠäœ¿çšãããŸããããããä»ã®å Žæã§äœ¿çšãããŸãããããã«ã€ããŠã¯ç¥ããŸããã
æ£èŠè¡šçŸãããã³ã°
ãã®ã¿ã€ãã®æ£èŠè¡šçŸãšã³ãžã³ã¯ãããããNCAïŒ é決å®çã¹ããŒããã·ã³ ïŒã䜿çšããŠå®è£ ãããŸãã äž»ãªå©ç¹ã¯ãïŒå¥ã®ååãšæ¯èŒããŠïŒå€æ°ã®æ©èœããµããŒãããŠããããšã§ãã åœç¶ããã®åçã«ã¯å€ãã®æ¬ ç¹ããããŸãã
第äžã«ãåäœæéã¯éåžžã«é·ããªãå¯èœæ§ããããŸãïŒå¥ã®åçãšæ¯èŒããŠïŒã å ¥åæååã®é·ãã®ææ°é¢æ°ç挞è¿ãŸã§ã å€ãã®äžè¬çãªãšã³ãžã³ã¯ãããã«å¯Ÿããä¿è·ããåããŠãããæ€çŽ¢ãäžæããŸãã
第äºã«ãNKAã¯æ£èŠè¡šçŸã®èšè¿°æ¹æ³ã«å€§ããäŸåããŸãã DFAãé²é³ã®åœ¢åŒã§ãŸã£ããåãã§ããå Žåãæéãšæ€çŽ¢çµæã¯åçã®åŒã§ãŸã£ããåãã«ãªããŸãããNKAã®å Žåãããã¯ãŸã£ããã®åé¡ã§ãã 1ã€ã®åŒã¯ææ°æŒžè¿ç·ãäžããããšãã§ãããã1ã€ã®åŒã¯ã»ãŒç·åœ¢ã§ãã ãããã£ãŠããã¿ãŒã³ãæé©åãããšããåé¡ã¯ãå®å šãªæé·ã«ãããŠçããŸãã NKAã¯çŸåšãã»ãšãã©ã®æ£èŠè¡šçŸãšã³ãžã³ã§äœ¿çšãããŠããŸãã
ã¯ã©ã·ãã¯NKAã®éèŠãªæ©èœã¯ãæåã®å®å šäžèŽãèŠã€ãããšããã«æ€çŽ¢ãäžæããããšã§ãã ã€ãŸã å Žåã«ãã£ãŠã¯ãæ€çŽ¢çµæã¯DKAãšã¯å€§ããç°ãªããŸãã ããã¯ã¢ã«ãŽãªãºã ã®æ©èœã§ãã
ããã§ã¯ããªããšã³ãžã³ã®äœè ã¯POSIXã«åŸãã®ãæ¥ãã§ããªãã®ã§ããããïŒ å®éãDKAæ€çŽ¢ã®ã»ãã³ãã£ã¯ã¹ã¯æšæºã§ä¿®æ£ãããŠããŸãã ã€ãŸã ãã¡ãããæåéãDKAã䜿çšãã¹ãã ãšã¯èšãããŠããŸãããããæ倧é·ã®å·Šç«¯ã®äžèŽãã«ã€ããŠèšãããŠããŸãã ããããNKAã¯æåã®ãã®ã ããè¿ããæ倧ã®é·ãã¯è¿ããŸããã ãããŠäœããã¹ããïŒ POSIXã«æºæ ããããã«ã圌ãã¯éåžžPOSIX NKAãšåŒã°ããã¢ã«ãŽãªãºã ã®ä¿®æ£ãæãã€ããŸããã ãããŠãããã¯åãªãNCAããããã£ãšé·ãæ©èœããŸãã æšæºãæºããããã«ã¯ãæ£èŠè¡šçŸã§èš±å¯ããããã¹ãŠã®ãªãã·ã§ã³ãå®è¡ããå¿ èŠãããããã§ãã ããã«ããªããã£ãšé·ãã®ãã説æããŸãã
ã³ã³ãã€ã«æžã¿ïŒDFAãšåãæå³ã§ãïŒNKAã¯ããã¿ãŒã³ã«åºã¥ããåœä»€ã§ããã·ãŒã±ã³ã·ã£ã«ã¢ã«ãŽãªãºã ã§ãã NCAã®äž»èŠãªæ©èœã¯ããªã¿ãŒã³ãã§ãã æ€çŽ¢é床ã¯ãã®æ°ã«çŽæ¥äŸåããŸãã
æ»ãå€ã¯ãäŸã§æããã説æãããŠããŸãã DFAã®äŸã§äœ¿çšãããã®ãšåã2è¡ãšåãæ£èŠè¡šçŸã䜿çšããŠã¿ãŸãããã
1è¡ç®ïŒ
- ãã¿ãŒã³
^
ã®æåã®ã¡ã¿ãã£ã©ã¯ã¿ãŒã¯ãäœçœ®ãè¡ã®å é ãšäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã - ãã¿ãŒã³ãaãã®2çªç®ã®æå-å€ãæååã®æåã®æåãšäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã
- ãã¿ãŒã³ãbãã®3çªç®ã®æå-æååã®2çªç®ã®æåãšå€ãäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã
- ãã¿ãŒã³ãcãã®4çªç®ã®æå-æååã®3çªç®ã®æåãšå€ãäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã
- 5çªç®ã®æååã®ã¡ã¿æå
\w
æååã®4çªç®ã®æåã®å€ãšäžèŽããŸãã æ°éè©ã«ã¯å°ãªããšã1ã€ã®æåãå¿ èŠãªã®ã§ãæ»ãå€ã¯ãããŸããã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã - æååã®5çªç®ã®ã¡ã¿æå
\w
æååã®5çªç®ã®æåã®å€ãšäžèŽããŸãã æ°éè©ã«ã¯ããã§ã«ãã£ããã£ãŒãããŠããå°ãªããšã1ã€ã®æåãå¿ èŠã§ãã ãã®æç¹ã§æãæ»ããè¡ãããå ŽåããããŸãã æ»ãã¹ã¿ãã¯ã«ã¯1ã€ã®èŠçŽ ãå«ãŸããŸãã
ãã®äžé段éã§ãNCAã¯äžèŽãšããŠè¡å šäœããabcdeããšèŠã€ããŸãããããã¿ãŒã³ã¯ãŸã æåŸãŸã§ééããŠããŸããã ãã¿ãŒã³ã®ã·ã³ãã«ãeãã¯ãŸã äžèŽããŠããŸããããã©ã€ã³ã®çŸåšäœçœ®ã¯ã·ã³ãã«ãeãã®åŸãã«ãããŸãã ãã®æç¹ã§æ¥œãã¿ãå§ãŸããŸãã æãèŠãŠãã ããã - ãã¿ãŒã³ãeãã®8çªç®ã®æåã¯ãæååã®6çªç®ã®æåãšå€ãäžèŽããŸãã ïŒåã«ååšããŸããïŒã äžèŽãèŠã€ãããŸããã æ»ãã¹ã¿ãã¯ã®ç¢ºèª-1ã€ã®ã¬ã³ãŒãããããŸãã è¿åãå®æœããŸãã æ»ã£ãåŸãè¡ã®ãeã·ã³ãã«ã®åãã®äœçœ®ã«ããããã¿ãŒã³ã®ãeã·ã³ãã«ã®åãã®äœçœ®ã«ããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã
NCAãäžèŽãæ€åºããªãå Žåããªã¿ãŒã³ã¹ã¿ãã¯ããã§ãã¯ããŸãã ãªã¿ãŒã³ãå®è¡ãããšãè¡ã®äœçœ®ã埩å ããããªã¿ãŒã³ãã¹ã¿ãã¯ããåé€ãããŸãã æ»ãã¹ã¿ãã¯ã空ã§äžèŽããªãå Žåãè¡ã®ãã®éå§äœçœ®ããã®äžèŽã¯ãªããšèŠãªãããŸãã
- ãã¿ãŒã³ãeãã®8çªç®ã®æå-å€ãæååã®5çªç®ã®æåãšäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã
- ãã¿ãŒã³
$
ã®9çªç®ã®ã¡ã¿ãã£ã©ã¯ã¿ãŒã¯ãäœçœ®ãè¡ã®çµãããšäžèŽããŸãã æ»ãã¹ã¿ãã¯ã¯ç©ºã§ãã - ãã¿ãŒã³ãçµäºããçŸåšäžèŽããŠããŸãã è¿åŽããŸãã
2çªç®ã®ã±ãŒã¹ã§äœãèµ·ãããïŒ
- ã¢ã«ãŽãªãºã ã®éå§ã¯ãŸã£ããåãã§ãããã«ãã¿ãŒã³ãeãã®8çªç®ã®æåã«ç§»åããŸãã
- ãã¿ãŒã³ãeãã®8çªç®ã®æå-å€ãæååã®5çªç®ã®æåãšäžèŽããŸãã ïŒç¹°ãè¿ããŸãããåã«ååšããŸããïŒã äžèŽãèŠã€ãããŸããã ãªã¿ãŒã³ã¹ã¿ãã¯ããã§ãã¯ããŸã-空ã§ãïŒåã®ã¹ãããã§ã¯ãéæå®å
+
ãå°ãªããšã1ã€ã®äžèŽãå¿ èŠãšããããããªã¿ãŒã³ã¹ã¿ãã¯ã«äœãè¿œå ããªãã£ãããã空ã§ãïŒã æãæ»ãã¯ã§ããŸããã è¡ãäžèŽããªãã£ããããçµæãè¿ããŸãã
ç解ãæ·±ããããã«ãæ°éè©
+
åžžã«ã§ããã ãå€ãã®è¡æåããã£ããã£ããããšã説æããŸãã ãããã£ãŠãæ倧ãšåŒã°ããŸãã åå¿è ãç¯ãããããééãã¯ããã«é¢é£ããŠããŸãã ãã¿ãŒã³
\(.+\)
ã¯ããããã¯ããã¹ãïŒå€§æ¬åŒ§ïŒãããã¯ããã¹ãïŒå€§æ¬åŒ§ïŒãããã¯ããã¹ãããšããéšåã§äžèŽã
\(.+\)
ãã©ã±ããïŒãã ãšããã®ã¯ãåŠç段éã§
.+
è¡å šäœãæåŸãŸã§ãã£ããã£ãããã·ã³ãã«ãïŒãã«å°éãããšããã«ãå®å šã«äžèŽãããã®ãããã«èŠã€ãããŸãã æ£èŠè¡šçŸãå°ãå€æŽããŠã¿ãŸãããïŒ
\([^)]+\)
ãããŠä»ã§ã¯ãç§ãã¡ãæ©ãŸãåé¡ã¯ãããããŸããã ããããå¥ã®ãã®ãç»å ŽããŸããïŒãããŠããããªãã§äœãèµ·ãããïŒã ããŠããããã«ããã¹ãããããŸãïŒãã©ã±ããïŒããã³å¥ã®ãã©ã±ããå ïŒããŸãããã¹ãïŒããããŠããã¹ãããããŸããããïŒãã©ã±ããïŒããã³å¥ã®ãã©ã±ããå ïŒïŒããšãã£ããã£ãããŸãããããããã¡ããæ£ãããããŸããããã£ããã£æ®µéã§ã¯ã2çªç®ã®éãæ¬åŒ§ã«å°éãããèŠã€ãã£ãäžèŽãããã«1çªç®ã®æ¬åŒ§ã«è¿ããŸããåé¡ã解決ããããšãã§ããŸã ãã©ã³ã¹ãã§ãã¯ïŒã€ãŸãããã§ãã¯ïŒã
å®éãã¢ã«ãŽãªãºã ãå ·äœçã«ã©ã®ããã«æ©èœãããã説æãããšããç§ã¯å°ããããã§ãã å®éã«ã¯ããšã³ãžã³ãæé©åãé©çšããå Žåããã®ããã«åäœããŸãïŒãã¿ãŒã³ã
^
æåã§å§ãŸãå Žåãè¡ã®å é ã§äžèŽãããããŸã£ããäžèŽããªãããšãæããã§ãïŒã å®éãåã®ã¹ãããã§å®å šã«äžèŽãããã®ã1ã€ãèŠã€ãããªãã£ãå Žåãæé©åãç Žæ£ããŠãããšã³ãžã³ã¯è¡ã®æ¬¡ã®åæåããå§ãŸããŸã£ããåãæ€çŽ¢ãå®è¡ããŸãã ã€ãŸã 2è¡ç®ã§ã¯ãé£ç¶ããŠ5åã®æ€çŽ¢ãå®è¡ããïŒæåãaãã®åããéå§ãã次ã«ãbãããcãããeããæåŸã®æåãeãã®åŸïŒããã®åŸã®ã¿äžèŽããªããšèšããŸãã DKAã¯ãã¹ãŠã®ã±ãŒã¹ã1ãã¹ã§åŠçããŸãã ããããå¶ç¶ã®äžèŽããªãNKAã«ã¯5ãå¿ èŠã§ãã
POSIX NKAãšã³ãžã³ã®éãã¯ãæåã®ã±ãŒã¹ïŒäžèŽãèŠã€ãã£ãå ŽåïŒã§ãæ€çŽ¢ãåæ¢ãããªãããšã§ãããäžèŽããªãå Žåã®ããã«ã5ã€ã®æ€çŽ¢ãã¹ãŠãå®è¡ãããŸãã
ãªã¿ãŒã³ãå®è¡ããææ³ãæ€èšããã®ã§ãææ°é¢æ°çæ€çŽ¢æéãã©ãããæ¥ãããæšæž¬ã§ããŸãã å Žåã«ãã£ãŠã¯ãã¢ã«ãŽãªãºã ããã©ããã«é¥ããèšå€§ãªæ°ã®ãªã¿ãŒã³ãçºçããŸãã ããšãã°ãåŒ
(\w+)*a
èããŸãã ãbbbãè¡ã«é©çšãããšãã©ããªããŸããïŒ æåã«ãæåã®æ°éè©
+
ã¯æååå šäœããã£ããã£ãã2çªç®ã®æ°éè©ã«å¶åŸ¡ãæž¡ããŸãã è¡ã«ãã以äžæåããªãããããã¿ãŒã³ã®ãaãæåã«ç§»åããŸãã è¡ã«ãªãå Žåã¯ã1æåãã€æ»ããæ°ããã°ã«ãŒãã§ç©ºããæåãã€ã³ã¿ãŒã»ãããããaãããã§ãã¯ããåã³äžèŽãããã®ããªããæ»ããŸãã ããã«ãæå³ã¯æ確ã§ãªããã°ãªããŸããã ãã®ã¢ã«ãŽãªãºã ã¯ã2ã€ã®æ°éè©ã«ãããã£ããã£ãŒã®ããã«ãèãããããã¹ãŠã®æ¹è¡ãå埩ããŸãã æååãbbbãã®å Žåããããã¯ã[bbb]ããã[bb] [b]ããã[b] [bb]ããã[b] [b] [b]ããšãããªãã·ã§ã³ã«ãªããŸãã è§æ¬åŒ§ã¯ãæ¡ä»¶ä»ãã§ãã£ããã£ãããã°ã«ãŒãã瀺ããŸãã ãã®å ŽåãããŒãã£ã·ã§ã³ã®æ°ã¯æååã®é·ãããææ°é¢æ°çã«å¢å ããŸãã
å¥ã®ç¶æ³ã 1ã¡ã¬ãã€ãã®ããã¹ããšãã¥ãŒãã¿ãŒã³ãæ³åããŠãã ãã
.*a
æ€çŽ¢ãããšã©ããªããŸããïŒ å段éã§ãæååã®ã¡ã¬ãã€ãå šäœããã£ããã£ããããaãæåãèŠã€ãããŸã§ã·ãŒã±ã³ã·ã£ã«ãªã¿ãŒã³ãå®è¡ãããŸãã ãããŠãæååã«ãã®ãããªæåããªãå Žåã¯ã©ããªããŸããïŒ ãã®åŸã1000001æ€çŽ¢ãå®è¡ããã ãã®ãã®ã«ãªããŸãã æ¯åãçŸåšã®æåããæåŸãŸã§ã®è¡å šäœããã£ããã£ããæåãaããèŠã€ãããŸã§ãã®è¡ã«æ»ããŸãïŒããã§ã¯ãããŸããïŒã ãããåé¿ããã«ã¯ããã®å Žå
[^a]*a
ãšæžãã ãã§ååã§ãã ããããããã¯ãã®å Žåã§ãã äžè¬çãªå ŽåïŒæ¬åŒ§ä»ãã®äŸã®ããã«ïŒãããã§ã¯ååã§ã¯ãããŸããã
ãªã¿ãŒã³ã®æé©åææ³ã«ã€ããŠã¯ãããã«å€ãã®ããšãæžããŠãã ããã 次ã®èšäºã§ã¯ãããã«å°å¿µããäºå®ã§ãã
æ¬ã Jeffrey FriedlãMastering Regular Expressions ãã«åºã¥ããŠããŸãã