1

For some reason, regex doesn't return a value. So, when I do a write-host $d[3], it doesn't return anything. But when I put the same regex in its own switch (without the domain, smtp, 5digit), it works fine. Why is that?

Function _getCountrySettings #Add additional countries to the switch statement
{
    param($CountryID)
    switch ($CountryID)
        {
           #"XX" {$d = ('user AD domain','*@ smtp domain','number of digits in the extension')}
            "ES" {$d = ('eurs.abc.net','*@es.abc.com','5digit','^(\+[3][4])?([1-9]\d\d{7})$')}          #Spain
            "CZ" {$d = ('eure.abc.net','*@cz.abc.com','5digit','^(\+[4][2][0])?([1-9]\d\d{7})$')}           #Czech Republic
            "UK" {$d = ('uk.eurw.abc.net','*@uk.abc.com','5digit')}                                     #UK
            "IE" {$d = ('eurw.abc.net','*@ie.abc.com','5digit')}                                            #Ireland        
    Default {write-host "[ERROR] Country Code not found"; exit}
        }
    return $d
}   
1
  • If your switch test is a regex, you have to add the -Regex parameter to the Switch statement. The default is use a literal string (not substring) match. Commented Jun 25, 2016 at 15:57

1 Answer 1

1

I just found

"ES" {$d = ('eurs.abc.net','*@es.abc.com','5digit') 

at the bottom of the switch. That's why ES wasn't returning the regex.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.