From: William James Date: 2006-08-02T16:15:09+09:00 Subject: Re: super-newbee Ruby regex help? Aaron Reimann wrote: > This is pretty complex considering that I am just now reading "Learn to > Program" by Chris Pine (it is a book teaching you how to program in > Ruby). It is very basic. I am somewhat good with PHP but and wanting > to move into RoR and want to learn Ruby before I learn Rails. > > Anyway, I found a real life situation where I think Ruby could do this > very quickly (and if I need to do it again, I can just run the script). > I need to remove some stuff from a text file. Simple huh? Here is > the site that I need the list from: > > http://edge.i-hacked.com/250-working-proxies-for-safe-web-access-from-work-or-school > > In that page there is one line of "code" that has all of the > links...here is part of it: > 3 Proxy || href="http://www.3proxy.net">3 Proxy || href="http://www.3proxy.org">3 Proxy > > I have taken just that line and saved that as a text file. > > I need to strip everything where I wind up with this: > 3proxy\.com > 3proxy\.net > 3proxy\.org > 4proxy\.com > > I will be taking that list (all 300 of them) and adding them to my > content filtering box. That way, all of these sites will be blocked. > > Do you guys know of any sites that might have a similar situation where > I can see the code? or have any of you done something similar? I can > probably modify stuff to make it fit my needs, but stuff like > http://www.regular-expressions.info/ruby.html doesn't give me enough > info to start. > > what i have right now is: file = File.open("list.txt","w") If the file already exists, you'll destroy it by using the "w" option. Since some of the anchor tags span more than one line, let's read the whole file at once: p IO.read( 'list.txt' ). scan( %r{