Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 查找引号之间的数字_Regex_Powershell - Fatal编程技术网

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)}}