Re: help with sed-friendly regex with negative look-ahead syntax for sendmail

"Cameron Simpson [email protected] [sed-users]" <[email protected]> Sat, 25 Feb 2017 07:42:12 +1100
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
On 23Feb2017 20:26, Rob Kudyba <[email protected]> wrote:
>If you look at the guide in http://www.xiitec.com/blog/2009/02/25/using-regular-expressions-in-sendmail/, the goal is to reject emails from certain top level domains, such as .info, .us. and .bid but only if they have a subdomain. So:
>good: [email protected], so *@*.usbad: [email protected], so *@*.*.us
>This regex works:[a-zA-Z_0-9.-]+\@[a-zA-Z_0-9-]+?\.+[a-zA-Z_0-9.-]+?\.(us|info|bid)
>I'm trying to include/append to the beginning of the above regex, a negative 
>look-ahead that would, in essence, ignore emails like:1) 
>[email protected] so *@ci.*.us2) [email protected] (and state is 
>one of the 50 states or DC) so *@*.ny.us (ny or any other state that is)

The simplest this would be to reject them as a separate prior stop.

In sed, something like:

  /\.info$/d
  /\.us$/d
  /things-your-would-otherwise-accept/{
    do whatever with those
  }

Don't put it all in one regexp.

Cheers,
Cameron Simpson <[email protected]>