我不确定这是如何工作的/它意味着什么......
my ($value) = ($out =~ /currentvalue[^>]*>([^<]+)/);
基本上,这是CURL / PERL脚本的一部分,它会进入www.example.com,并在页面html中找到<{1}}
。
脚本的<span id="currentvalue"> GETS THIS VALUE </span>
部分到底是做什么的?它是否定义了它寻找span id =&#34; ..&#34; ?
我在哪里可以了解有关[^&gt;] *&gt;([^&lt;] +)/)函数的更多信息?
答案 0 :(得分:8)
/.../
又名m/.../
是匹配运算符。它检查其操作数(在=~
的LHS上)是否与文字中的正则表达式匹配。运营商记录在perlop中。 (转到“m / PATTERN /”。)正则表达式记录在perlre。
至于这里使用的正则表达式,
$ perl -MYAPE::Regex::Explain \
-e'print YAPE::Regex::Explain->new($ARGV[0])->explain' \
'currentvalue[^>]*>([^<]+)'
The regular expression:
(?-imsx:currentvalue[^>]*>([^<]+))
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
currentvalue 'currentvalue'
----------------------------------------------------------------------
[^>]* any character except: '>' (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
> '>'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[^<]+ any character except: '<' (1 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
答案 1 :(得分:7)
这是普通的Perilla regexp。见tutorial
/ # Start of regexp
currentvalue # Matches the string 'currentvalue'
[^>]* # Matches 0 or more characters which is not '>'
> # Matches >
( # Captures match enclosed in () to Perl built-in variable $1
[^<]+ # Matches 1 or more characters which is not '<'
) # End of group $1
/ # End of regexp