qræ¼ç®å - æ£è¦è¡¨ç¾ã®ãªãã¡ã¬ã³ã¹ãä½æãã
ããqræ¼ç®åãã§正規表現ã®ãªãã¡ã¬ã³ã¹ãä½æãããã¨ãã§ãã¾ããqræ¼ç®åã使ãã¨ãæ£è¦è¡¨ç¾ããªãã¡ã¬ã³ã¹ã¨ãã¦å¤æ°ã«ä¿åã§ãã¾ããæ£è¦è¡¨ç¾ã®ãªãã·ã§ã³ãå«ãã¦ä¿åã§ãã¾ããæ£è¦è¡¨ç¾ããã³ã³ãã¤ã«ãããã®ã§ãç¹°ãè¿ããã¿ã¼ã³ããããè¡ãå ´åãé«éã«åä½ãã¾ãã
# æ£è¦è¡¨ç¾ã®ãªãã¡ã¬ã³ã¹ my $regex = qr/\d+/sm;
ããã¿ã¼ã³ããããè¡ãã¨ãã¯//ã®ä¸ã«å ¥ãããã¨ãã§ãã¾ããããã®ã¾ã¾ä½¿ç¨ãããã¨ãã§ãã¾ãã//ã®ä¸ã«ãããã»ããå°ãè¦ããã¨æãã¾ãã
# //ã®ä¸ã§ä½¿ç¨ if ($str =~ /$regex/) { ... } # ãã®ã¾ã¾ä½¿ç¨ if ($str =~ $regex) { ... }
ãªãã¡ã¬ã³ã¹ã£ã¦ä½?
ãªãã¡ã¬ã³ã¹ã«ã¤ãã¦ã¯ä»¥ä¸ã®è¨äºã§è©³ãã解説ãã¦ãã¾ãã
- リファレンスã®ä½¿ãæ¹ããã¹ã¿ã¼ããã
ãµã³ãã«
ãæ£è¦è¡¨ç¾ã®ãªãã¡ã¬ã³ã¹ã使ã£ããµã³ãã«ã§ãã
use strict; use warnings; # qr// ã使ãã¨ãªãã·ã§ã³ãå«ãã¦å¤æ°ã«ä¿åã§ãã¾ãã # (gãªãã·ã§ã³ã¯ãæå®ã§ãã¾ããã) my $word = "ababab"; my $regex = qr/A/i; my $replace = 'c'; $word =~ s/$regex/$replace/g; print "\$word = $word\n";
ãå®è¡çµæã
$word = cbcbcb
Perl
›
ãªãã¡ã¬ã³ã¹
›
æ¼ç®å
›
here