Powershell using Regex finding a string within a string
Need help using regex and powershell to accomplish the following. I have the following example string:
<INPUT TYPE="hidden" NAME="site2pstoretoken" VALUE="v1.2~04C40A77~23"\><INPUT TYPE="hidden" NAME="p_error_code" VALUE="">
The only thing I want to extract from this example string is the hash stored in VALUE. The hash is very long so I need to catch everything between VALUE=开发者_运维百科" ....HASH.... "\>
How will the regex look like?
Try this one with warning, that parsing html with regexes is bad idea:
$regex = [regex]'(?<=VALUE=")[^"]*'
$regex.Match('te2pstoretoken" VALUE="v1.2~04C40A77~23"\><INP').Value
Edit: And this code works as well:
if ('te2pstoretoken" VALUE="v1.2~04C40A77~23"\><INP' -match '(?<=VALUE=")[^"]*') {
$matches[0]
}
精彩评论