Share via


Scripting Tips & Tricks: Dynamic RegEx Queries

Another week of RegEx! I just can't get enough of it at the moment. A bit like sleep. I said sleep, not sheep!

Man, I do like a good sleep. I'm writing this at an airport. It's way past my bedtime.

Anyway... what do I have for you this week? Well, I feel like a kleptomaniac at the moment. This one comes from a customer that wants to remain anonymous. You know who you are!

Want to insert a dynamic value into a regex statement? No problem, PowerShell laps this stuff up!

 

 
Regex "w+\d{$param}$" 

 

This one checks for characters at the start of the string and then a specific number of digits at the end of the string. The number being supplied by $param. Nice.

RegEx and sleep... hmmm, no correlation intended!