The problem with your script is here :
Where-Object {$_ -match '(?is)(?<=\bNAME1\b).*?(?=\bNAME2\b|\bNAME3\b|NAME4|NAME5|NAME6\b)'}
This doesn’t mean “keep the matches”, but “if there is a match, keep the entire string”.
Here is another way to do what you want :
$text = Get-Content .\withoutStar.txt
$regex = "(?is)(?<=\bNAME1\b).*?(?=\bNAME[2-6]\b)"
Set-Content .\AllfunctionGroup.txt -Value ""
(Select-String -Pattern $regex -Input $text -AllMatches).Matches | ForEach {
Add-Content .\AllfunctionGroup.txt $_.Value
}
Edit : I simplified a bit your regex
solved Unable to get data between multiple keyword using powershell