繁体   English   中英

Perl / Curl脚本中的Perl正则表达式

[英]Perl regular expression in Perl/Curl script

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

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

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

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

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

/.../ aka 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
----------------------------------------------------------------------

这是普通的Perilla regexp。 请参阅本教程

  /              # 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM