Created
March 19, 2012 01:16
-
-
Save mgng/2088861 to your computer and use it in GitHub Desktop.
文字列正規表現コンパイル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = 'abcd123'; | |
$reg = '/^abc/'; | |
if ( preg_match( $reg, $str ) ) { | |
echo 'match!'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $str = 'abcd123'; | |
my $reg = "/^abc/"; | |
if ( $str =~ $reg ) { | |
print 'match!'; # ここ通らない | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $str = 'abcd123'; | |
my $reg = "/^abc/"; | |
my $reg_obj = eval( "qr$reg" ); # ←←←←ココ | |
if ( $str =~ $reg_obj ) { | |
print 'match!'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment