I have tab delimited data in an array and applying the regex match as shown below i am able to get the id value as required.
However the $matches
variable returns two values and they are the same value.
$data = @(
'name1 "1001" role1',
'name2 "1002" role2'
)
foreach($d in $data)
{
$d -match '(?<=")(.*)(?=")' | out-null #search for id in quotes
$id = $matches[0]
#...
}
When I check $matches
I get 2 same matches instead of 1 -
PS C:\> $matches
Name Value
---- -----
1 1002
0 1002
I am a regex beginner. I got the regex string to apply from here (Regex Match all characters between two strings).
So I either need to tweak my regex logic or there is a reason why $matches
returns two same values for a single match. I tried searching for a relevant answer but was not able to find an article to explain this. Can someone please advice on what is happening?