PowerShell: regex



cd C:\Sandbox\PowerShell
# this returns true
 $regex = [regex]"xxx"
# both the next match because {u?} means that u may occur, or may not occur
 $regex = [regex] "colou?r"
# both match because { (i|e) ) means that those are mandatory alternatives at that character position
 $regex = [regex]"art(i|e)fact"

Running a regex on dates is far more involved. My advice would be to write a .net class/method, and or a date tryparse, with the challenging bit often being the locale and the many possible formats.

Removing blank lines (not strictly PowerShell)




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s