From: Phrogz Date: 2007-09-08T03:25:09+09:00 Subject: Re: Reg Ex On Sep 6, 4:58 pm, Charles Pareto wrote: > I'm querying through the .com's looking for any www name with Cisco in > it. > I'm using a reg exp that is reading a file line by line obtained by > Verisign that has all the domain names with a .com extension. > Here is my reg exp: > > file.each { |line| print line if line =~ /(C|c)isco|CISCO/ } > > but I'm getting results like SanFrancisco and Francisco. > > Does anyone know how I can modify my reg exp to not include certain > keywords like SanFrancisco and Francisco? Instead of modifying the regex, how about simply working on the data until it's right? ACCEPTABLE = [ /francisco/i, /scisco/i ] matches = file.readlines.select{ |line| line =~ /[Cc]isco|CISCO/ } ACCEPTABLE.each{ |re| matches.delete_if{ |line| line =~ re } } puts matches