Rabu, 20 Juli 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})$

lamsim

About lamsim

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :