我正在查看一位前雇员编写的脚本,并遇到了这个问题。我很困惑这意味着什么。这是一个遍历文件的 if 循环的条件,我知道 $rr 变量是什么,但之后的一切我都不知道它是什么意思......显然谷歌搜索“\d”没有返回任何相关......什么“.+>”也是这个意思吗?
if ($line =~ m/($rr)(.+>)(\d.\d+)</) {
我使用了x
修饰符来使模式具有描述性:
$line =~ m/
( $rr ) # Match and capture the value of $rr
( .+ > ) # Match and capture everything till the last >
( # Capture the following matches
\d # Match a single digit
. # Match any character a single time
\d+ # Match one or more digits
)
/x;
上述模式中有三个捕获。可以使用特殊变量$1
和访问这些$2
捕获$3
。
这是关于正则表达式的。
if ($line =~ m/($rr)(.+>)(\d.\d+)
$line
是一个变量。它与这种模式匹配
的方式是什么?
模式如下。它类似于then 变量,然后(单个字符),(多次匹配前一个字符)。我不确定。表示一个数字(即 0 到 9)。=~
m/
$rr
.
+
>
\d
在此处阅读模式匹配和正则表达式:http ://en.wikipedia.org/wiki/Regular_expression
正则表达式在许多语言中都是相似的,例如 Perl、Ruby 等。
在此处查看您的大部分字符串(ruby):http ://rubular.com/r/OTe4jFN545
如果 line 匹配以 $rr 变量开头的正则表达式,后跟至少一个任意字符,后跟至少两位数。
我怎么不确定,但它接缝缺少一个括号。
我会尝试去这里匹配正则表达式
http://www.perlfect.com/articles/regextutor.shtml
正则表达式是 m/($rr)(.+>)(\d.\d+ 但这接缝错误 /($rr)(.+>)(\d.\d+)/ 接缝更好。正则表达式也有捕获可以在 if 语句中访问的组
$_[0] .. $_[2]