[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Charles Pareto

9/6/2007 10:59:00 PM

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?


-Chuck
--
Posted via http://www.ruby-....

6 Answers

Xavier Noria

9/6/2007 11:13:00 PM

0

On Sep 7, 2007, at 12:58 AM, 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?

You need to assert word boundaries:

/\b((C|c)isco|CISCO)\b/

-- fxn


S P Arif Sahari Wibowo

9/6/2007 11:48:00 PM

0

Robert Klemme

9/7/2007 9:54:00 AM

0

2007/9/7, Diego Suarez <diego.suargarcia@gmail.com>:
> The boundaries could be a good idea, but if he needs urls like
> ciscosystems.com, with the final \b won't match. Keep that in sight :)
>
> On 9/7/07, S P Arif Sahari Wibowo <arifsaha@yahoo.com> wrote:
> >
> > On Fri, 7 Sep 2007, Charles Pareto wrote:
> > > file.each { |line| print line if line =~ /(C|c)isco|CISCO/ }
> > ...
> > > Does anyone know how I can modify my reg exp to not include
> > > certain keywords like SanFrancisco and Francisco?
> >
> > How about:
> > /\b([Cc]isco|CISCO)\b/
> >
> > or even
> >
> > /\bcisco\b/i

I'd probably use a second rx like

file.each { |line| print line if line =~ /\bcisco/i && line !~ /sanfrancisco/i}

Kind regards

robert

Jimmy Kofler

9/7/2007 4:27:00 PM

0

> Posted by Charles Pareto (chuckdawit) on 07.09.2007 00:58
> 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?
>
>
> -Chuck
> Reply with quote


Maybe also try something like: print line if line =~
/^(?!.*(?:SanFrancisco|Francisco)).*\Bcisco/i


Cheers

j.k.
--
Posted via http://www.ruby-....

Phrogz

9/7/2007 6:24:00 PM

0

On Sep 6, 4:58 pm, Charles Pareto <chuckda...@gmail.com> 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

Charles Pareto

9/11/2007 9:43:00 PM

0

Gavin Kistner wrote:
> On Sep 6, 4:58 pm, Charles Pareto <chuckda...@gmail.com> wrote:
>> 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




If I want to print the line to a new file I use this:
dnsfile.each { |line| newfile.puts line if line =~
/(\b((C|c)isco|CISCO)\b) /

what can I do if I want to print it to a newfile and print it to the
screen at the same time?

--
Posted via http://www.ruby-....