Skip to content

Instantly share code, notes, and snippets.

@mgng
Created March 19, 2012 01:16
Show Gist options
  • Save mgng/2088861 to your computer and use it in GitHub Desktop.
Save mgng/2088861 to your computer and use it in GitHub Desktop.
文字列正規表現コンパイル
<?php
$str = 'abcd123';
$reg = '/^abc/';
if ( preg_match( $reg, $str ) ) {
echo 'match!';
}
#!/usr/bin/perl
use strict;
use warnings;
my $str = 'abcd123';
my $reg = "/^abc/";
if ( $str =~ $reg ) {
print 'match!'; # ここ通らない
}
#!/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