I have a file which looks like this:
x: 0
y:1
z: 4
THe output after parsing should be below. The idea is to split it on colon+space. If the lien begins with white space it is part of the value otherwise it is Id.
ID is x, Value is "0 y:1"
ID is z, Value is "4"
I have the following code for parsing and it doesn't seem to work. I validate the regular expression here and it seems to work.
My guess is it is syntax. I would appreciate any ideas on this. Thanks,
#$pattern = [regex]"(?m)((\S+)[^:'n]*:(\s+)(.+)'n)((\s+)(.+)'n)*"
#$pattern = [regex]"(?m)((\S+)[^:'n]*:(\s+)(.+)'n)((\s+)(.+)'n)*"
$pattern = [regex]"((\S+)[^:'n]*:(\s+)(.+)'n)((\s+)(.+)'n)*"
$content.split($pattern,[System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object {
$split = $_.split(":", 2)
if ($split -eq $null ) {return }
if ($split[0] -ne $null) {$Name=$split[0].Trim()} else {return }
if ($split[1] -ne $null) { $Id = $split[1].Trim() } else {return }
Write-host "#Name is- $Name #Id is- $Id"
}