"Hello Justin"
-match
"justin"
#
true
,
default
is
insensitive
-cmatch
false
case
does not match
-imatch
explicit
insensitivity
The PowerShell Match operator will return a True or False value depending on if the source matches the provided pattern. Great for use with Where or If statements.
"The number 7 is great!"
-Match
"\d"
There is an automatic variable created upon a match called $Matches
"Hello Justin, Welcome"
"hello\s(\w+), welcome"
"My name is $($matches[1])"
The $Matches variable is a collection of match results from the pattern. Index 0 is the string that was matched and after that its the match group which is anything with in ( )
"hello world"
-replace
"world"
"World"
"today is 04/13/1999"
"\d{2}/\d{2}/\d{4}"
, (
get
-date -f
"MM/dd/yyyy"
)
Regex Replace Using Found matches
"justin.rich@technet.com"
"^(\w+)\.(\w+)@"
'$1-$2@'
Regex replace using found matches next to numbers
"jrich532"
"(\d)\d{2}"
"`${1}23"
Depending on what sort of matching you need to do, there can be a very significant difference in the performance of regex. Patterns themselves can have an impact on the speed as well.
Nice set of resources learning regular expression for powershell.
Useful resources.
Thanks for sharing :)
I was looking for something like this, thanks for making this wiki Rich
jrich edited Revision 8. Comment: created basic structure, will populate data
jrich edited Revision 10. Comment: updated Match (saving work)
Very useful resources, thanks a lot
joakimbs edited Revision 13. Comment: Promoting my article, since I frankly think it deserves mention here.
Ed Price - MSFT edited Revision 15. Comment: White space tweaks