[英]Using regular expression extractor to extract a value?
I am trying to extract the value from the following code.
我试图从以下代码中提取值。 Even though my regex expression is fine it is still not extracting the value.
即使我的正则表达式很好,它仍然没有提取值。
token" value="(.+?)"
this does give me the exact match which I checked using regex101.com 这确实给了我使用regex101.com检查的完全匹配
<input type="hidden" name="token" value="GSYGEP2UUWOTMZ2SFV1G5D2M8L247KIG">
what the regex expression should be 正则表达式应该是什么
Try this 尝试这个
<input(?=(?:[^>"']|"[^"]*"|'[^']*')*?\sname\s*=\s*(['"])\s*token\s*\1)(?=(?:[^>"']|"[^"]*"|'[^']*')*?\svalue\s*=\s*(['"])((?:(?!\2)[\S\s])*)\2)\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]*?)+>
The Value content you're after is in Capture Group 3
您所追求的价值内容位于
Capture Group 3
https://regex101.com/r/HJhStT/1 https://regex101.com/r/HJhStT/1
https://regex101.com/r/8BWONb/1 https://regex101.com/r/8BWONb/1
Explained 解释
< input # Input tag
(?= # Name attribute: Assert (a pseudo atomic group)
(?: [^>"'] | " [^"]* " | ' [^']* ' )*?
\s name \s* = \s* # name =
( ['"] ) # (1), Quote
\s* token \s* # token
\1
)
(?= # Value attribute
(?: [^>"'] | " [^"]* " | ' [^']* ' )*?
\s value \s* = \s* # value =
( ['"] ) # (2), Quote
( # (3 start), value content
(?:
(?! \2 )
[\S\s]
)*
) # (3 end)
\2
)
# Just get rest of tag
\s+
(?: " [\S\s]*? " | ' [\S\s]*? ' | [^>]*? )+
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.