Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Fwd: Re: Re: Parse problem

From: pwawood:mango:my at: 9-Oct-2005 12:30

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