I am using regular expression to find strings in Powershell, and match function returns empty string lines as well as matched lines.
For the following four lines of text file input.txt,
[abc]
abc
[123]
123
The code below prints out abc/blank line/123/blank line. I expected it only prints out abc and 123, wonder how this happened.
$readArray = Get-Content(input.txt)
foreach($line in $readArray) {
$re = [regex] *** // Find the string in bracket
$key = $re.match($line)
if($key -ne $null) {
write-host -$key.group[1].value
}
}

$re = [regex] ***looks like some kind of mistake. Can you post the actual regex you're using?