2

我不太确定这是如何工作的/这意味着什么......

my ($value) = ($out =~ /currentvalue[^>]*>([^<]+)/);

所以基本上,这是 CURL/PERL 脚本的一部分,它进入 www.example.com,并
<span id="currentvalue"> GETS THIS VALUE </span>
在页面 html 中找到。

[^>]*>([^<]+)/)脚本的部分究竟是做什么的?它是否定义它正在寻找 span id=".." ?

在哪里可以了解有关 [^>]*>([^<]+)/) 函数的更多信息?

4

2 回答 2

8

/.../akam/.../是匹配运算符。它检查其操作数(在 的 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
----------------------------------------------------------------------
于 2013-11-05T16:30:05.810 回答
7

这是普通的 Perl 正则表达式。看这个教程

  /              # 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
于 2013-11-05T16:30:12.150 回答