powershell will strip a collection/array every chance it gets.. and
that usually happens at the pipeline boundary, but also expressions
like $() and functions effectively work the same way...
so i did this
$a = ([regex]"this").Matches("this is a test")
and i see that it is a matchcollection
# count should be one, but nothing...
$b = (regexmatch "this" "this is a test")
while is stripping the one itemed collection to just the match, and the
type returned in the actual match. so to maintain the array/collection
we can adjust your function with the , which will force it not to be
stripped. (or rather wrap it in an array, so that only that wrapped
array gets stripped)
function regexmatch($instr1, $instr2){
,$([regex]$instr1).Matches($instr2)
}
will do the trick..