[REBOL] Re: replacing urls in html using parse function...
From: gscottjones:mchsi at: 2-Sep-2002 5:58
From: "Holzammer, Jean"
<snip>
> a: {assas href="http://www.ann.lu" dfdfdf src="http://bla.org" fdfdf}
> parse/all a [any [ [[thru {href="}] | [thru {src="}]] copy text to {"}
> (print text)]]
> parse/all a [any [ [[thru {href="}] | [thru {src="}]] position1: to {"}
> position2: (change/part position1 "neu" position2 print position2)]]
> parse/all a [any [ [[thru {href="}] | [thru {src="}]] position1: to {"}
> position2: (change/part position1 "neu" position2 print position1 print
> position2 print "")]]
<snip>
Hi, Jean,
Andrew's response came in just as I was finishing my hack. As he points
out, there are hazards in changing the string (or block) which is being
parsed: it throws off the index, in short (my words). Before I understood
what exactly what is going on with this type of (logic) error, I got into
the habit of creating new strongs (or blocks) out of the old ones. It
somehow lacks the elegance, but is easier for me to see what I am doing. So
here is a different way to accomplish the same thing:
a: {assas href="http://www.ann.lu" dfdfdf src="http://bla.org" fdfdf}
new-html: copy ""
parse/all a [
any [
copy blob
[[thru {href="}] | [thru {src="}]]
(
new-html: join new-html blob
new-html: join new-html "neu"
)
to {"}
]
copy blob
to end
(new-html: join new-html blob)
(print new-html)
]
--Scott Jones