Author Posts

January 19, 2017 at 6:16 pm

I am working with the following match statement:

$folder -match "[A-Z][A-Z][A-Z][A-Z][A-Z0-9]_*"

However, it does not work the way I would it expect to work. I would expect


to be false, and


to be true.

Unfortunately, both arguments are true. How can I test if the 6th position is an underscore (_) and not anything else ?


January 19, 2017 at 7:06 pm

This should do it:


^ marks the begin
[A-Za-z] = All A-Z ad a-z
{5} = 5 times [A-Za-z]
[_] = an underscore

January 19, 2017 at 7:09 pm

$Regex = '[A-Z]{5}_.+'
$folder1 -match $Regex
$folder2 -match $Regex

January 19, 2017 at 7:15 pm

Thanks, works like a charm!