in reply to Req expression translation

It's essentially a broken attempt to match an email address ending in "@myinfo.com"

Let's start with the "@myinfo.com/" part. The dot is going to match any character, so it could, in fact, match "@myinfo9com" At least the dot and @ should be escaped like this: "\@myinfo\.com/"

The other problem is the [\w.-]+ character class, which will let in any amount of dots or hyphens or word characters, in any order. Imagine an email address like this: "---...@myinfo.com". This RE will allow that.

The RE would be more effective like this:

/^(?:[\w\d]+[.-]?)+\@myinfo\.com$/

While that might still reject a potentially valid address, or accept a potentially invalid address, at least it's limited to one server, and will be acceptible 99% of the time.


Dave

Replies are listed 'Best First'.
Re: Re: Req expression translation
by dragonchild (Archbishop) on Dec 12, 2003 at 18:39 UTC
    An even better way could be:
    use Email::Valid; unless ( $thing_to_check =~ /\@myinfo\.com/ && Email::Valid->address($thing_to_check) ) { print "'$thing_to_check' is not valid!\n"; }

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.