Regex 查找引号之间的数字
所以我有这一行,好几行Regex 查找引号之间的数字,regex,powershell,Regex,Powershell,所以我有这一行,好几行 <drives name="drive 1" deviceid="\\.\PHYSICALDRIVE0" interface="SCSI" totaldisksize="136,7"> 这将匹配136,7,但不是1367 有可能两者都匹配吗 谢谢。只需将正则表达式中的,作为可选项,在,旁边添加?量词即可 $(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d
<drives name="drive 1" deviceid="\\.\PHYSICALDRIVE0" interface="SCSI" totaldisksize="136,7">
这将匹配136,7,但不是1367
有可能两者都匹配吗
谢谢。只需将正则表达式中的
,
作为可选项,在,
旁边添加?
量词即可
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+,?\d+)".*','$1'
或
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+(?:,\d+)*)".*','$1'
正则表达式:
( group and capture to \1:
\d+ digits (0-9) (1 or more times)
(?: group, but do not capture (0 or more
times):
, ','
\d+ digits (0-9) (1 or more times)
)* end of grouping
) end of \1
当然可以:
注:。它会腐蚀你的灵魂,让猫女们痛苦地死去。是的,我真的不懂演示。我的脑子就是不懂语法。如果它也必须匹配136.7呢?谢谢你,太棒了。我很感激。
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+(?:,\d+)*)".*','$1'
( group and capture to \1:
\d+ digits (0-9) (1 or more times)
(?: group, but do not capture (0 or more
times):
, ','
\d+ digits (0-9) (1 or more times)
)* end of grouping
) end of \1
$xmlfile = 'C:\path\to\output.xml'
& cscript sydi-server.vbs -t. -ex -o$xmlfile
[xml]$sysinfo = Get-Content $xmlfile
$driveinfo = $sysinfo.SelectNodes('//drives') |
select name, @{n='DiskSize';e={[Double]::Parse($_.totaldisksize)}}