Reputation: 187
So I have this line, well several.
<drives name="drive 1" deviceid="\\.\PHYSICALDRIVE0" interface="SCSI" totaldisksize="136,7">
and
<drives name="drive 1" deviceid="\\.\PHYSICALDRIVE0" interface="SCSI" totaldisksize="1367">
I have this line which match the the number between the quotes:
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+,\d+)".*','$1'
Which will match 136,7 but not 1367.
Is it possible to match both?
Thank you.
Upvotes: 1
Views: 407
Reputation: 200273
Sure:
$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)}}
Note: Do not parse XML with regular expressions. It will corrupt your soul and make catgirls die in pain.
Upvotes: 2
Reputation: 174706
Just make the ,
in your regex as optional by adding the ?
quantifier next to ,
.
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+,?\d+)".*','$1'
OR
$(Select-String totaldisksize $Path\*.xml).line -replace '.*totaldisksize="(\d+(?:,\d+)*)".*','$1'
Regular Expression:
( 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
Upvotes: 0