Wednesday, July 20, 2016

PowerShell v2 RegEx Examples

There are countless examples of regex with PowerShell. (one of the best Ive seen:
PowerShell - Working With Regular Expressions (regex)
These are really mainly for me so I dont have to reinvent the wheel in a pinch. As the list grows hopefully it will help others.
  • Match last 6 characters in string: "1234567890" -match "(.{6})$"
  • Match file paths without having to escape slashes with double slashes: $_.fullname -replace [Regex]::Escape("C: est est"),
  • Match IPv4 address: "255.255.255.255" -match "([0-2][0-9][0-9]).([0-2][0-9][0-9]).([0-2][0-9][0-9]).([0-2][0-9][0-9])"
  • Match spaces or $null values: $_ -match "s+|^$"
  • MAC address^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger