none
Trouble with regex matching RRS feed

  • Question

  • In my code snipped (see below), I want to check that the value of $InternalEmailAddress is in the format of something@something.something. No matter what I put into $InternalEmailAddress, it never evaluates to "true".  I used the tester at https://regex101.com/ and I can make it match, but never in Powershell. Any thoughts on what I'm doing wrong?

        If (($ExternallyAvailable -eq $True) -AND ($InternalEmailAddress -notmatch "[[:alnum:]+_+\.]+@[[:alnum:]+_+\.]+\.+[[:alnum:]]{2,62}")) {
            While ($InternalEmailAddress -notmatch '[[:alnum:]+_+\.]+@[[:alnum:]+_+\.]+\.+[[:alnum:]]{2,62}') {
                $InternalEmailAddress = Read-Host "Please enter an e-mail address"
            }
        }
    Thanks.

    Friday, March 25, 2016 10:38 PM

Answers

  • IRL the length of first level domain name can be more than 4 characters (e.g http://www.jamclub.moscow)

    So for the better matches you can change pattern to '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$'


    my blog: http://shserg.ru/

    • Marked as answer by mhashemi Saturday, March 26, 2016 4:05 PM
    Saturday, March 26, 2016 8:00 AM

All replies

  • $emailPattern = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$'

    $emailaddress -match #emailPattern


    \_(ツ)_/

    Friday, March 25, 2016 10:58 PM
  • IRL the length of first level domain name can be more than 4 characters (e.g http://www.jamclub.moscow)

    So for the better matches you can change pattern to '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$'


    my blog: http://shserg.ru/

    • Marked as answer by mhashemi Saturday, March 26, 2016 4:05 PM
    Saturday, March 26, 2016 8:00 AM