One of the most useful tools a scripter has at their disposal is Regular Expressions. The problem is that regular expressions can seem like Greek and for most folks learning them can seem an impossible task. I hope this blog post provides those people some hope as well as some tools they can use to tackle this mountain one foot at a time.
NOTE: I would like to make this blog entry as dynamic as possible, so if you have your own tips… let me know and I will add them.
Everyone is different, but this is how I went about learning Regular Expressions
- Phase one: Learn EXACTLY what a regular expression is and what it can and can NOT do.
- Phase two: Learn the syntax. I printed out the RegEx Cheet Sheet and use it daily.
- Phase three: Find a purpose. I find if I actually have a problem I spend more energy on learning.
- Phase four: Create a simple Regular Expression.
- Phase five: Build on your Regular Expression.
- Phase six: Trouble shooting the Regular Expression.
- First things first… Click here and watch the vids
- Keep a cheat sheet close at hand!
- Take them in small bites. I hope to blog in detail about this later, but lets just say string concatenation is your friend
- Keep it simple!
- $matches is your friend! $matches is an object that Powershell creates when you make a RegEx call (like -match.)
- Google It. Chances are there is Regex already out there for what you need.
- Using Lables can save you time by extracting certain data and making it a property on $matches.
- RichardP from IRC says “Dont eat yellow snow?” Apparently he has experience in this area.
Good Blog Entries:
MoW at it again.
One Response to “Regular Expression Info and Tips for Powershell”
Leave a Reply
You must be logged in to post a comment.