When using -Match how do scalars/collections differ?

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 5 months ago.

  • Author
  • #5056

    by willsteele at 2012-08-29 09:21:16

    I have found that -match operator does not always work with the $Matches object. For instance, if I use this command,
    @(1,2,3) -match "\d"
    and then check $Matches it is empty. Based on this, I have always wondered: what are the rules for when $Matches gets written to and when it does not get written to?

    by poshoholic at 2012-08-29 09:30:06

    AFAIK the rule is simple: if you are using -match against a single item that is a collection, even if it is a collection of only one item, then $matches is not written to. If you are using -match against a single item that is not a collection, then $matches is written to.

    by willsteele at 2012-08-29 11:23:54

    You were exactly right Kirk. Thanks for the clarification. I got it now.

You must be logged in to reply to this topic.