Date: Tuesday April 23, 2019 @ 22:57 Author: argrath Update of /cvsroot/perldocjp/docs/perl/5.26.1 In directory sf-cvs:/tmp/cvs-serv87127/perl/5.26.1 Modified Files: perlretut.pod Log Message: 5.26.1/perlretut =================================================================== File: perlretut.pod Status: Up-to-date Working revision: 1.2 Tue Apr 23 13:57:45 2019 Repository revision: 1.2 /cvsroot/perldocjp/docs/perl/5.26.1/perlretut.pod,v Existing Tags: No Tags Exist -------------- next part -------------- Index: docs/perl/5.26.1/perlretut.pod diff -u docs/perl/5.26.1/perlretut.pod:1.1 docs/perl/5.26.1/perlretut.pod:1.2 --- docs/perl/5.26.1/perlretut.pod:1.1 Tue Apr 9 02:03:35 2019 +++ docs/perl/5.26.1/perlretut.pod Tue Apr 23 22:57:45 2019 @@ -62,16 +62,14 @@ =end original Àµµ¬É½¸½¤È¤Ï²¿¤Ç¤·¤ç¤¦¤«? -Àµµ¬É½¸½¤È¤Ï¥Ñ¥¿¡¼¥ó¤òɽ¤¹Ã±½ã¤Êʸ»úÎó¤Ç¤¹¡£ -At its most basic, a regular expression -is a template that is used to determine if a string has certain -characteristics. The string is most often some text, such as a line, -sentence, web page, or even a whole book, but less commonly it could be -some binary data as well. -Suppose we want to determine if the text in variable, C<$var> contains -the sequence of characters S<C<m u s h r o o m>> -(blanks added for legibility). We can write in Perl -(TBT) +ºÇ¤â´ðËÜŪ¤Ê°ÕÌ£¤Ç¤Ï¡¢Àµµ¬É½¸½¤È¤Ïʸ»úÎ󤬤¢¤ëÆÃħ¤ò»ý¤Ã¤Æ¤¤¤ë¤«¤ò +·èÄꤹ¤ë¤¿¤á¤Ë»È¤ï¤ì¤ë¥Æ¥ó¥×¥ì¡¼¥È¤Ç¤¹¡£ +ʸ»úÎó¤Ï¤Û¤È¤ó¤É¤Î¾ì¹ç¡¢¹Ô¡¢Ê¸¡¢web ¥Ú¡¼¥¸¡¢¤¢¤ë¤¤¤ÏËÜÁ´ÂΤΤ褦¤Ê¤Ê¤ó¤é¤«¤Î +¥Æ¥¥¹¥È¤Ç¤¹¤¬¡¢¤Þ¤ì¤ËǤ°Õ¤Î¥Ð¥¤¥Ê¥ê¤Î¾ì¹ç¤â¤¢¤ê¤Þ¤¹¡£ +ÊÑ¿ô C<$var> ¤ËÆþ¤Ã¤Æ¤¤¤ë¥Æ¥¥¹¥È¤¬Ê¸»úÊÂ¤Ó +S<C<m u s h r o o m>> (¶õÇò¤ÏÆɤߤ䤹¤µ¤Î¤¿¤á¤ËÄɲ䷤Ƥ¤¤Þ¤¹)¤ò +´Þ¤ó¤Ç¤¤¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤¿¤¤¤È¤·¤Þ¤¹¡£ +Perl ¤Ç¤Ï¼¡¤Î¤è¤¦¤Ë½ñ¤±¤Þ¤¹: $var =~ m/mushroom/ @@ -94,20 +92,21 @@ =end original -The value of this expression will be TRUE if C<$var> contains that -sequence of characters, and FALSE otherwise. The portion enclosed in -C<'E<sol>'> characters denotes the characteristic we are looking for. -We use the term I<pattern> for it. The process of looking to see if the -pattern occurs in the string is called I<matching>, and the C<"=~"> -operator along with the C<m//> tell Perl to try to match the pattern -against the string. Note that the pattern is also a string, but a very -special kind of one, as we will see. +¤³¤Î¼°¤ÎÃͤϡ¢C<$var> ¤¬¤³¤Îʸ»úʤӤò´Þ¤ó¤Ç¤¤¤ë¤Ê¤é¿¿¤Ë¡¢¤µ¤â¤Ê¤±¤ì¤Ð +µ¶¤Ë¤Ê¤ê¤Þ¤¹¡£ +C<'E<sol>'> ʸ»ú¤Ç°Ï¤Þ¤ì¤¿Éôʬ¤Ï¡¢Ãµ¤·¤Æ¤¤¤ëÆÃħ¤ò°ÕÌ£¤·¤Æ¤¤¤Þ¤¹¡£ +¤³¤ì¤ò I<¥Ñ¥¿¡¼¥ó> (pattern) ¤È¸Æ¤Ó¤Þ¤¹¡£ +¥Ñ¥¿¡¼¥ó¤¬Ê¸»úÎó¤ÎÃæ¤Ë¤¢¤ë¤«¤É¤¦¤«¤òõ¤¹½èÍý¤ò I<¥Þ¥Ã¥Á¥ó¥°> (matching) ¤È +¤è¤Ó¡¢ +C<m//> ¤È¶¦¤Ë C<"=~"> ±é»»»Ò¤¬»È¤ï¤ì¤ë¤È¡¢Perl ¤Ïʸ»úÎó¤ËÂФ·¤Æ¥Ñ¥¿¡¼¥ó¤ò +¥Þ¥Ã¥Á¥ó¥°¤·¤Þ¤¹¡£ +¥Ñ¥¿¡¼¥ó¤âʸ»úÎó¤Ç¤¹¤¬¡¢´û¤Ë¸«¤é¤ì¤¿¤È¤ª¤ê¡¢¤È¤Æ¤âÆüì¤Ê¼ïÎà¤Ç¤¢¤ë¤³¤È¤Ë +Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£ ¥Ñ¥¿¡¼¥ó¤Ïº£Æü¹¤¯»È¤ï¤ì¤Æ¤¤¤Þ¤¹; ¤¿¤È¤¨¤Ð¡¢¥¦¥§¥Ö¥Ú¡¼¥¸¤ò¸«¤Ä¤±½Ð¤¹¤¿¤á¤Ë ¸¡º÷¥¨¥ó¥¸¥ó¤Ë¥¿¥¤¥×¤·¤¿¤ê¡¢¥Ç¥£¥ì¥¯¥È¥ê¤ÎÃæ¤Î¥Õ¥¡¥¤¥ë¤ò ¥ê¥¹¥È¥¢¥Ã¥×¤¹¤ë¤¿¤á¤Ë "C<ls *.txt>" ¤È¤« "C<dir *.*>" ¤È¤·¤¿¤ê¤·¤Þ¤¹¡£ -Perl¤Ç¤Ï¡¢¥Ñ¥¿¡¼¥ó¤ÏÀµµ¬É½¸½¤Ë¤è¤Ã¤Æµ½Ò¤µ¤ì¡¢Ê¸»úÎó¤òõ¤·¤À¤¹¤À¤±¤Ç¤Ê¤¯¡¢ +Perl ¤Ç¤Ï¡¢¥Ñ¥¿¡¼¥ó¤ÏÀµµ¬É½¸½¤Ë¤è¤Ã¤Æµ½Ò¤µ¤ì¡¢Ê¸»úÎó¤òõ¤·¤À¤¹¤À¤±¤Ç¤Ê¤¯¡¢ ʸ»úÎó¤Î˾¤ß¤ÎÉôʬ¤ò¼è¤ê½Ð¤·¤¿¤ê¡¢¸¡º÷¤ÈÃÖ´¹¤ÎÁàºî¤ò¤¹¤ë¤¿¤á¤Ë¤â»È¤ï¤ì¤Þ¤¹¡£ -(TBT) =begin original @@ -125,15 +124,14 @@ =end original Àµµ¬É½¸½¤Ë¤ÏÃê¾ÝŪ¤ÇÍý²ò¤¹¤ë¤Î¤¬Æñ¤·¤¤¤È¤¤¤¦ÉÔŬÀڤʰ̾¤¬¤¢¤ê¤Þ¤¹¡£ -This really stems simply because the -notation used to express them tends to be terse and dense, and not -because of inherent complexity. We recommend using the C</x> regular -expression modifier (described below) along with plenty of white space -to make them less dense, and easier to read. +¤³¤ì¤ÏËÜÅö¤Ïñ¤Ëɽ¸½¤Ë»È¤ï¤ì¤Æ¤¤¤ëµË¡¤¬´Ê·é¤«¤Äǻ̩¤Ç¤¢¤ë¤«¤é¤Ç¤¢¤Ã¤Æ¡¢ +ËܼÁŪ¤ÊÊ£»¨À¤Ë¤è¤ë¤â¤Î¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ +¥Ñ¥¿¡¼¥ó¤ÎÌ©ÅÙ¤ò¸º¤é¤·¡¢¤è¤êÆɤߤ䤹¤¯¤¹¤ë¤¿¤á¤Ë¡¢ +C</x> Àµµ¬É½¸½½¤¾þ»Ò (¸å½Ò¤·¤Þ¤¹) ¤È¶¦¤Ë¤¿¤¯¤µ¤ó¤Î¶õÇò¤ò»È¤¦¤³¤È¤ò +´«¤á¤Þ¤¹¡£ Àµµ¬É½¸½¤Ï¾ò·ï¤È¥ë¡¼¥×¤Î¤è¤¦¤Êñ½ã¤Ê¥³¥ó¥»¥×¥È¤ò»È¤Ã¤Æ¹½À®¤µ¤ì¤Æ¤¤¤Æ¡¢ Perl ¼«¿È¤Î C<if> ¤Ç¤¢¤ë¤È¤« C<while> ¤Î¤è¤¦¤Ê¤½¤ì¤ÈÂбþ¤¹¤ë¤â¤Î¤ËÈæ¤Ù¤Æ Æñ¤·¤¤¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¡£ -(TBT) =begin original @@ -262,7 +260,7 @@ =end original -Àµµ¬É½¸½Ãæ¤Î¥ê¥Æ¥é¥ëʸ»úÎó¤ÏÊÑ¿ô¤ËÃÖ¤´¹¤¨¤ë¤³¤È¤â¤¬¤Ç¤¤Þ¤¹: +Àµµ¬É½¸½Ãæ¤Î¥ê¥Æ¥é¥ëʸ»úÎó¤ÏÊÑ¿ô¤ËÃÖ¤´¹¤¨¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹: my $greeting = "World"; if ("Hello World" =~ /$greeting/) { @@ -441,7 +439,7 @@ =end original "2+2=4" =~ /2+2/; # ¥Þ¥Ã¥Á¥ó¥°¤·¤Ê¤¤; + ¤Ï¥á¥¿Ê¸»ú - "2+2=4" =~ /2\+2/; # ¥Þ¥Ã¥Á¥ó¥°¤¹¤ë; \+ ÉáÄ̤Π+ ¤Î¤è¤¦¤Ë°·¤ï¤ì¤ë + "2+2=4" =~ /2\+2/; # ¥Þ¥Ã¥Á¥ó¥°¤¹¤ë; \+ ¤ÏÉáÄ̤Π+ ¤Î¤è¤¦¤Ë°·¤ï¤ì¤ë "The interval is [0,1)." =~ /[0,1)./ # ¤³¤ì¤Ïʸˡ¥¨¥é¡¼! "The interval is [0,1)." =~ /\[0,1\)\./ # ¥Þ¥Ã¥Á¥ó¥°¤¹¤ë "#!/usr/bin/perl" =~ /#!\/usr\/bin\/perl/; # ¥Þ¥Ã¥Á¥ó¥°¤¹¤ë @@ -500,14 +498,14 @@ =end original -In situations where it doesn't make sense for a particular metacharacter -to mean what it normally does, it automatically loses its -metacharacter-ness and becomes an ordinary character that is to be -matched literally. For example, the C<'}'> is a metacharacter only when -it is the mate of a C<'{'> metacharacter. Otherwise it is treated as a -literal RIGHT CURLY BRACKET. This may lead to unexpected results. -L<C<use re 'strict'>|re/'strict' mode> can catch some of these. -(TBT) +ÆÃÄê¤Î¥á¥¿Ê¸»ú¤¬Ä̾ï¤Î°ÕÌ£¤È¤·¤Æ°ÕÌ£¤Î¤Ê¤¤¾õ¶·¤Ç¤Ï¡¢ +¼«Æ°Åª¤Ë¥á¥¿Ê¸»úÀ¤¬¤Ê¤¯¤Ê¤ê¡¢ +¥ê¥Æ¥é¥ë¤Ë¥Þ¥Ã¥Á¥ó¥°¤¹¤ëÄ̾ï¤Îʸ»ú¤Ë¤Ê¤ê¤Þ¤¹¡£ +Î㤨¤Ð¡¢C<'}'> ¤ÏÁê¼ê¤È¤Ê¤ë C<'{'> ¥á¥¿Ê¸»ú¤¬¤¤¤ë¾ì¹ç¤Ë¤Î¤ß +¥á¥¿Ê¸»ú¤Ë¤Ê¤ê¤Þ¤¹¡£ +¤µ¤â¤Ê¤±¤ì¤Ð¤³¤ì¤Ï¥ê¥Æ¥é¥ë¤Ê RIGHT CURLY BRACKET ¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹¡£ +¤³¤ì¤ÏÁÛÄê³°¤Î·ë²Ì¤ò°ú¤µ¯¤³¤¹¤«¤â¤·¤ì¤Þ¤»¤ó¡£ +¤³¤ì¤é¤Î°ìÉô¤Ï L<C<use re 'strict'>|re/'strict' mode> ¤ÇÊ᪤Ǥ¤Þ¤¹¡£ =begin original @@ -3553,10 +3551,10 @@ =end original -Starting in Perl v5.26, specifying C</xx> changes the square-bracketed -portions of a pattern to ignore tabs and space characters unless they -are escaped by preceding them with a backslash. So, we could write -(TBT) +Perl v5.26 ¤«¤é¡¢C</xx> ¤ò»ØÄꤹ¤ë¤È¡¢µÕ¥¹¥é¥Ã¥·¥å¤òÁ°ÃÖ¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ +¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤¸Â¤ê¡¢¥¿¥Ö¤È¥¹¥Ú¡¼¥¹¤Îʸ»ú¤ò¤ò̵»ë¤¹¤ë¤è¤¦¤Ë +¥Ñ¥¿¡¼¥ó¤ÎÂ礫¤Ã¤³¤Ç°Ï¤Þ¤ì¤¿Éôʬ¤òÊѹ¹¤·¤Þ¤¹¡£ +½¾¤Ã¤Æ¡¢¼¡¤Î¤è¤¦¤Ë½ñ¤±¤Þ¤¹: /^ [ + - ]?\ * # first, match an optional sign @@ -3578,10 +3576,9 @@ =end original -This doesn't really improve the legibility of this example, but it's -available in case you want it. Squashing the pattern down to the -compact form, we have -(TBT) +¤³¤ì¤Ï¤³¤ÎÎã¤ÎÆɤߤ䤹¤µ¤òËÜÅö¤Ë²þÁ±¤·¤Æ¤Ï¤¤¤Þ¤»¤ó¤¬¡¢ +»È¤¤¤¿¤¤¾ì½ê¤Ç¤ÏÍøÍѲÄǽ¤Ç¤¹¡£ +¥³¥ó¥Ñ¥¯¥È¤Ê·¿¼°¤Ë¥Ñ¥¿¡¼¥ó¤ò°µ½Ì¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹: /^[+-]?\ *(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/; @@ -6855,7 +6852,7 @@ Translate: KIMURA Koichi Update: SHIRAKATA Kentaro <argra****@ub32*****> (5.10.0-) -Status: in progress +Status: completed =end meta