请教perl语言,/(\d{4}(\-?
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 12:02:02
请教perl语言,/(\d{4}(\-?请教perl语言,/(\d{4}(\-?请教perl语言,/(\d{4}(\-?这一正则在尝试寻找连续4个数字,及1个可有可无的-(横杠)但值得留意的是,这里有
请教perl语言,/(\d{4}(\-?
请教perl语言,/(\d{4}(\-?
请教perl语言,/(\d{4}(\-?
这一正则在尝试寻找 连续 4 个数字,及 1 个可有可无的 - (横杠)
但值得留意的是,这里有两组 () ,在括号中能找到匹配的文字时,会顺序存到 $1,$2 ...中
$str = "1234";
$str /(\d{4}(\-?))/ ;
if ( $1 and $2 ) { print "\$1 = '$1',\$2 = '$2'.number with - " }
elsif ( $1 ) { print "\$1 = '$1',\$2 = '$2'.number only" }
else { print "not matched" }
print "$/$/";
$str = "9876-";
$str /(\d{4}(\-?))/ ;
if ( $1 and $2 ) { print "\$1 = '$1',\$2 = '$2'.number with - " }
elsif ( $1 ) { print "\$1 = '$1',\$2 = '$2'.number only" }
else { print "not matched" }