Powershell 使用 Regex 在字符串中查找字符串 [英] Powershell using Regex finding a string within a string

查看:50
本文介绍了Powershell 使用 Regex 在字符串中查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助使用正则表达式和 powershell 来完成以下操作.我有以下示例字符串:

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="">

我想从这个示例字符串中提取的唯一内容是存储在 VALUE 中的哈希值.散列很长,所以我需要捕获 VALUE=" ....HASH .... ">

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?

推荐答案

尝试这个并警告,用正则表达式解析 html 是个坏主意:

$regex = [regex]'(?<=VALUE=")[^"]*'
$regex.Match('te2pstoretoken" VALUE="v1.2~04C40A77~23"\><INP').Value

这段代码也能正常工作:

And this code works as well:

if ('te2pstoretoken" VALUE="v1.2~04C40A77~23"\><INP' -match '(?<=VALUE=")[^"]*') { 
   $matches[0] 
}

这篇关于Powershell 使用 Regex 在字符串中查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆