Bonjour Patrick
Thanks for posting the parse solution. It's certainly shorter than my
do-it-yourself approach.
At the moment it seems as though it doesn't work properly if an url is in
the string twice:
>> s: {I love http://www.rebol.com, I hate http://www.rebol.com}
== {I love http://www.rebol.com, I hate http://www.rebol.com}
>> bs: parse s none
== ["I" "love" "http://www.rebol.com" "I" "hate" "http://www.rebol.com"]
>> remove-each w bs [not parse to-block w [url!]]
== ["http://www.rebol.com" "http://www.rebol.com"]
>> foreach w bs [
[ replace find s w w rejoin [{<a href="} w {">} w {</a>}]
[ ]
== {<a
href="http://www.rebol.com">http://www.rebol.com</a>">http://www.rebol.com</
a>
, I hate http://www.rebol.com}
You need to add something to the foreach loop so that you don't find the
first occurrence of the url when looking for the second.
I came up with this, which no doubt can be vastly improved upon:
>> foreach w bs [
[ replace find s w w rejoin [{<a href="} w {">} w {</a>}]
[ s: next find next find s w w
[ ]
== "ttp://www.rebol.com</a>"
>> s: head s
== {I love <a href="http://www.rebol.com">http://www.rebol.com</a>, I hate
<a href="h
ttp://www.rebol.com">http://www.rebol.com</a>}
Salut
Peter
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 09 October 2005 02:36
To: Rebol-List
Subject: [REBOL] Fwd: Re: Re: Parse problem
Bonjour Peter,
Thank you for your code. Being a lazy guy, I was hoping to get advantage of
block parsing. Block parsing is able to match a type, the type being url! in
my case.
Example :
>> ablock: [foo dummy http://www.me.com foo] parse ablock [ some [set u
>> url! (print u) | skip]]
http://www.me.com
So finally, my solution is :
s: {Go see http://www.me.org, it is
fabulous. And http://aaa.mypicture.com with my photos}
bs: parse s none
remove-each w bs [not parse to-block w [url!]]
foreach w bs [
replace find s w w rejoin [{<a=href"} w {">} w {</a>}]
]
print s
Go see <a=href"http://www.me.org">http://www.me.org</a>, it is fabulous. And
<a=href"http://aaa.mypicture.com">http://aaa.mypicture.com</a> with my
photos
I'm pretty sure this code is not optimized and that some guru could make a
one liner of it. Anyway it will do the job the way I like.
--
Ciao
Patrick
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/123 - Release Date: 06/10/2005
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/123 - Release Date: 06/10/2005
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.