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

"[email protected] [sed-users]" <[email protected]> 25 Feb 2017 08:41:46 +0000
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
POSIX "sed" not only does not support lookarounds but also has a different notation for quantifiers. 

 And how I look at lookarounds is that they are positional and they constrain your existing regexs to make them look at things with a finer focus.
 

 So with that rough idea we can rework your negative lookaround regex in regular Sed syntax as follows:
 

 

 /[a-zA-Z_0-9.-]+<@[a-zA-Z_0-9-]+?\.+[a-zA-Z_0-9.-]+?\.(us|info|to|br|bid|cn|ru)/
 

 We'll break it up and look at individual portions starting from L->R:
 

      [a-zA-Z_0-9.-]+ => [a-zA-Z_0-9.-]\{1,\}

 

      <    =>     <
 

      @    =>     @
 

      [a-zA-Z_0-9-]+?     =>   [a-zA-Z_0-9-]
 

      \..+     => \..\{1,\}  
 

       [a-zA-Z_0-9.-]+?     =>   [a-zA-Z_0-9.-]
 

 

       \.(us|info|to|br|bid|cn|ru)  => \.\(us\|info\|to\|br\|bid\|cn\|ru\)
 

 

 So the regex becomes as a first pass(despite how it looks the below is all on one line and there are NO spaces at all)/
 

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.(us\|info\|to\|br\|bid\|cn\|ru\)/

 

 

 Now we have to constrain it some more for it to restrict somewhat, akin to tightening a water tap but not completely closing it off:
 


   /regex_above/{
       

         /.*\@.*\..\.ny.us$/d
           
        /.*\@ci\..\.us$/d
 

       # add some more here per taste
 

   ## what appears here is negative look arounded effectively.
 

   }
 

 Keep in mind that /regex_above/ is for GNU sed and not POSIX sed.
 

 For POSIX sed you would need  to break it up piece by piece, like as:
 

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.us/bA
 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.info/bA

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.to/bA

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.br/bA

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.bid/bA

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.cn/bA

 /[a-zA-Z_0-9.-]\{1,\}<@[a-zA-Z_0-9-]\..\{1,\}[a-zA-Z_0-9.-]\.ru/bA

 d
 #
 :A
 

 /.*\@.*\..\.ny.us$/d
 /.*\@ci\..\.us$/d

 ## add more negative lookahead constraints here
 

 ## what appears here is negative look arounded effectively

 

 

 

 NOTE: I did not verify the veracity of the regexes as I have used as u gave here. Some of them look suspect (could be due to mailer issues) but you need to take a careful n closer look at them.
 

 

 HTH
 



[Non-text portions of this message have been removed]