Forum OpenACS Q&A: conditional regsub

Collapse
Posted by Gilbert Wong on
I'm trying to do a conditional regsub of some html pages.  I want to
prefix all local file references with a directory path and ignore all
external references (ie http://).  For instance, I want change:

<img src="test.jpg" border="0">

to:

<img src="/some_directory/test.jpg" border="0">

Here is the regsub code I came up with:

regsub -all -nocase {(<img.+?src=).*?([^/" ]+)[" ]*(.*>)} $body "
"$new_path/" " body

However, I want to exclude it from modifying:

<img src="http://www.somerandomdomain.com/test.jpg" border="0">

Again, I want to modify all local references to images and leave all
external references alone.  Any ideas?

Collapse
Posted by Gilbert Wong on
Nevermind.  After messing around with it some more, this seems to produce the correct behavior:

regsub -all -nocase {(<img.+?src=)"*?([^http:/" ]+)[" ]*(.*>)} $body ""$new_path/" " body