Updates from: 07/15/2021 03:17:59
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About Comparison Operators (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Comparison_Operators.md
Scalar examples:
``` If the input is a collection, the operators return the matching members of that
-collection and the `$Matches` automatic variable is `$null`.
+collection.
Collection examples:
Collection examples:
#Output: Bag, Beg ```
-`-match` and `-notmatch` support regex capture groups. Each time they run, they
-overwrite the `$Matches` automatic variable. When `<input>` is a collection the
-`$Matches` variable is `$null`. `$Matches` is a **Hashtable** that always has a
-key named '0', which stores the entire match. If the regular expression
-contains capture groups, the `$Matches` contains additional keys for each
-group.
+`-match` and `-notmatch` support regex capture groups. Each time they run on
+scalar input, and the `-match` result is **True**, or the `-notmatch` result is
+**False**, they overwrite the `$Matches` automatic variable. `$Matches` is a
+**Hashtable** that always has a key named '0', which stores the entire match.
+If the regular expression contains capture groups, the `$Matches` contains
+additional keys for each group.
Example:
User name:
jsmith ```
+When the `-match` result is **False**, or the `-notmatch` result is **True**,
+or when the input is a collection, the `$Matches` automatic variable is not
+overwritten. Consequently, it will contain the previously set value, or `$null`
+if the variable has not been set. When referencing `$Matches` after invoking
+one of these operators, consider verifying that the variable was set by the
+current operator invocation by using a condition statement.
+
+Example:
+
+```powershell
+if ("<version>1.0.0</version>" -match '<version>(.*?)</version>') {
+ $Matches
+}
+```
+ For details, see [about_Regular_Expressions](about_Regular_Expressions.md) and [about_Automatic_Variables](about_Automatic_Variables.md).
module Index https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/module/index.md
archive_url: ''
layout: ApiBrowserPage apiPlatform: powershell quickFilterColumn1: powershell-7.1,windowsserver2019-ps
-quickFilterColumn2: azps-6.2.0,win-mdop2-ps
+quickFilterColumn2: azps-6.2.1,win-mdop2-ps
quickFilterColumn3: sqlserver-ps,systemcenter-ps-2019 ---