Advertisement
pedronrivera

Regular Expression Examples

Sep 6th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Regular Expression Example
  2. # \d matches only digits
  3.  
  4. # This code will only match the first digits it finds and stop after that
  5. "abcd345fhbfhnfrj123" -match "\d+"
  6.  
  7. # This code will match the all digits
  8. "abcd345fhbfhnfrj123" -match "(\d+)"
  9.  
  10. # Using the regular expressions will always populate the $Matches variable
  11. $Matches
  12.  
  13. # Matching an email address
  14. "first.lastname@company.com" -match "([a-z]+)\.[a-z]+@[a-z]+\.com"
  15.  
  16. # Match only letters
  17. "abcdefghijkmnopqrstuvwxyz0123456789" -match "\w+[^\d]"
  18.  
  19. # Parse Log Files and return the files with a specific IP (-SimpleMatch Parameter treats the string as non regex query)
  20. Get-Childitem -Recurse -Include *.log | select-string -Pattern "10.211.55.30" -SimpleMatch -List
  21.  
  22. # Parse Log Files and return the files with a specific IP (RegEX)
  23. Get-Childitem -Recurse -Include *.log | select-string -Pattern "\s(\d{1,3})\."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement