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?

0

1 Answer 1

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] 
}
Sign up to request clarification or add additional context in comments.

1 Comment

@stej: What's the difference between using Match().Value and Match().Groups[index].Value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.