[英]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.