I have a little Problem with my dry practice.
source
Code: Select all
test (aaa-b-cc11)
test (aaa-b-cc11)
test (aaa-b-cc12)
www-b-cc13
zzz-b-cc14
test (aaa-b-cc11)
www-b-cc13
Code: Select all
aaa-b-cc11
aaa-b-cc12
www-b-cc13
zzz-b-cc14
Code: Select all
$result = $doc.SelectNodes("//Object") | Where-Object {($_.Name -like '*-b-cc1*')} | %{$_.Name} | %{ $_ -Replace '^.*([a-z]{3}-b-cc1[1-4])$','$1' } | Sort-Object -Unique
$result
with the following replace the resultlist is ok
Code: Select all
$result = $doc.SelectNodes("//NCPObject") | Where-Object {($_.Name -like '*-b-cc1*')} | % { $_.Name } | % { ([String]$_).Replace("Test","")} | % { ([String]$_).Replace(" (","")} | % { ([String]$_).Replace(")","")} | Sort-Object -Unique
The second static way:
Code: Select all
$result = $doc.SelectNodes("//NCPObject") | Where-Object {($_.Name -like '*-b-cc1*')} | Select-Object -ExpandProperty Name | %{
if($_.Length -gt 10){
($_).Substring(5,10)
}
} | Sort-Object -Unique
But if the RegEx will work I can ignore the static ways.
Where is the error in reasoning?
regards