我只是在一个例子中遇到这个时浏览了perldocs( http://perldoc.perl.org/perlre.html#regular-expressions - 请参阅捕获组示例)

"aa" =~ /${a}/; # True
"aa" =~ /${b}/; # True
"aa0" =~ /${a}0/; # False!
"aa0" =~ /${b}0/; # True
"aa\x08" =~ /${a}0/; # True!
"aa\x08" =~ /${b}0/; # False
.

我找不到任何关于该语法意味着的文档。

所以在此上下文中,正则表达式/ $ {a} /均值是什么?

有帮助吗?

解决方案

$括号避免了变量名的歧义。这样:

$foo = 'house';
'housecat' =~ /$foo/;      # matches
'cathouse' =~ /cat$foo/;   # matches
'housecat' =~ /${foo}cat/; # matches
.

还在您所提供的链接中,有一个A和B的定义,但您忘记在此复制。

其他提示

需要从$a消除生成的$a0。请注意,令牌化器是贪婪的,因此变量名称是最长序列。如果在可变插值中的另一个字母或数字,则需要${name}语法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top