Estou tentando dividir um texto multilinha por uma palavra. O problema é que -split "(?=Name\s*:)"
não inclui espaços em branco antes do 'Nome'. "(?=\s*Name\s*:)"
Ele divide linhas vazias, assim como"(?m)(?=^\s*Name\s*:)"
$text = @"
Players:
Name : Matt
Height : 195
Weight : 100
Name : Keith
Height : 185
Weight : 85
Name : David
Height : 175
Weight : 85
"@
# Split the text by the word "Name" and keep the word in the next part,
$text = $text -split "(?=Name\s*:)"
# Remove the part before the first occurrence of "split"
$text= $text[1..($text.Length - 1)]
$index = 1
foreach($part in $text)
{
Write-Host "---------------------------------------"
Write-Host "Player $($index):"
$index++
$part
}
O Nome está no início da linha, não no mesmo lugar que Altura e Peso.
---------------------------------------
Player 1:
Name : Matt
Height : 195
Weitht : 100
---------------------------------------
Player 2:
Name : Keith
Height : 185
Weight : 85
---------------------------------------
Player 3:
Name : David
Height : 175
Weight : 85