Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Make regex example commands use single-quoted strings #5417
Unless PowerShell's string expansion is truly required, it's good habit to form and recommend to other to use single-quoted strings for:
The reason is that
The linked topic and
For instance, a current example command is:
# Should be: # 'Gobble' -replace 'Gobble', '$& $&' "Gobble" -replace "Gobble", "$& $&"
This happens to work, because
A somewhat contrived example to show that
$1 = 'hi' # I've seen such variable names in the wild 'Gobble' -replace 'Go(bb)le', "$& $1" # !! $1 is expanded *by PowerShell*
That is, instead of returning
If expansion is needed before the regex engine sees the result, the pass-through instances should be
$var = 'hi' 'Gobble' -replace 'Go(bb)le', "`$& $var `$1" # -> 'Gobble hi bb'
In general, I suggest using quoting consistently in all examples:
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.