为什么以下模式匹配成功?我错过了什么吗?
$a="pattern";
if($a =~ /[0-9]*/){
print "Contains\n";
}
Run Code Online (Sandbox Code Playgroud)
dev*_*ull 10
该*量词匹配0或更多.并且模式确实匹配零位数.
您可能希望使用+哪个表示匹配1次或更多次.
引用自perldoc perlre:
Quantifiers
The following standard quantifiers are recognized:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |