3

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?

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
DeChinees
  • 295
  • 6
  • 20

1 Answers1

3

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] 
}
stej
  • 27,607
  • 11
  • 68
  • 102