Grepping with Python - script/prog required.

Mike Rovner mike at nospam.com
Tue Jun 24 02:52:30 CEST 2003


John Fitzsimons wrote:

> I want to search an ordered text file and list web links such as :
> and Output like ;
>
> ftp://ftp.eunet.bg/pub/simtelnet
> http://clients.net2000.com.au/~johnf/faq
> www.fourmilab.ch/annoyance-filter/
>
> Can anyone suggest the code and/or a python program/script I could
> adapt to do this please ?

That's very dirty (with high false positive and negative hits) url
recognizer:

import re
url=re.compile(r'(?<=\s)(?:(?:ftp|http|https)://|www(?:\.[^\. ]+){2,}).*?(?=
\s)')
print '\n'.join(re.findall(url, your_text_goes_here))

Enjoy!
Mike








More information about the Python-list mailing list