SE Michigan PowerShell Users Group - Regex Part1

Post on 24-May-2015

1,632 views 1 download

Tags:

transcript

Matt JohnsonSE Michigan PowerShell Script Club

matt@michiganpowershell.com

Introduction Simple Pattern Searches Simple Pattern Examples Introduction to Regular Expressions Closing

Used with both operating system commands and PowerShell commands.

Using cmd.exe we used “*” and “?”. With PowerShell we get a few more options.

Also work with -like and –notlike

Simple Pattern Wildcards

Turns out this is a basic form of regular expressions

Wildcard Description

* Any number of characters

? Exactly one character

[xyz] One of the specified characters

[x-z] One of the characters in the specified area

Dir *.txt

Dir [li]*

$ip = 192.168.23.1If ($ip –like “*.*.*.*”) {“Valid”} Else {“Invalid”}

From Wikipedia: “Regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters.”

Found in some programming / scripting languages, editors and utilities.

Programming Languages: PowerShell, Perl, .NET languages, C++

Editors: Visual Studio, emacs

Utilities: grep, Power Grep

Websites:◦ http://www.regular-expressions.info/

Websites:◦ www.regexlib.com

Websites:◦ MSDN Regex Class

Books◦ Mastering Regular Expressions by Jeffrey Friedl◦ Regular Expressions Cookbook by Jan Goyvaerts,

Steven Levithan

Applications◦ Rad Software Regular Expression Designer◦ http://www.radsoftware.com.au

Applications◦ Ultrapico Expresso 3.0◦ http://www.ultrapico.com/expresso.htm

Applications◦ The Regex Coach◦ http://weitz.de/regex-coach

PowerShell and Regular expressions PowerShell and .NET’s Regex class Regular Expression Examples

Contact Me:Matt Johnson, GSEC, MCSEEmail: matt@michiganpowershell.comBlog:

http://www.packetcrazy.com/blogSocial Sites: mwjcomputing

- Twitter, Friendfeed, Facebook