[Tutor] String searching

André Dahlqvist andre@beta.telenordia.se
Wed, 31 May 2000 11:42:30 +0200


Hi everyone,

I'm trying to find out if a certain word in a string is a hyperlink, in
other words if it starts with http:// or ftp://. I've come up with a
way that works, but I think there must be some less uglier way of doing
this. Here's the solution I use now:

for word in string.split(text):
	if "http://" == word[0:7] or "ftp://" == word[0:6]
		do stuff with word...

The test itself is what I think is ugly, and I would have prefered to
use something like:

if "http://" or "ftp://" in string.split(text):
	get the whole word that matched...

But I don't know how to get this whole match. I would be greatful for
any advice.
-- 

// André

===================================================================
André Dahlqvist <andre@beta.telenordia.se>
GnuPG Key ID:	0x70A2994A
Fingerprint: 	E947 3297 331C CA30 5B88  EDF2 A830 3EBE 70A2 994A
===================================================================