提取两个双引号之间的所有数据 [英] Extract all data in between two double quotes
问题描述
我正在尝试使用 powershell 正则表达式从 AssemblyInfo.cs 文件中提取版本数据.下面的正则表达式是我最好的尝试,但它只提取字符串 [assembly: AssemblyVersion("
. 我已经把这个正则表达式放入几个 web 正则表达式测试器中,它看起来像我想要的那样,然而,这是我第一次使用 powershell 正则表达式,所以我可能看错了.
I'm trying to use a powershell regex to pull version data from the AssemblyInfo.cs file. The regex below is my best attempt, however it only pulls the string [assembly: AssemblyVersion("
. I've put this regex into a couple web regex testers and it LOOKS like it's doing what I want, however this is my first crack at using a powershell regex so I could be looking at it wrong.
$s = '[assembly: AssemblyVersion("1.0.0.0")]'
$prog = [regex]::match($s, '([^"]+)"').Groups[1].Value
推荐答案
您还需要包含开始的双引号,否则它会从头开始捕获,直到到达第一个 "
.>
You also need to include the starting double quotes otherwise it would start capturing from the start until the first "
is reached.
$prog = [regex]::match($s, '"([^"]+)"').Groups[1].Value
^
这篇关于提取两个双引号之间的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!