PDA

View Full Version : Regular Expressions Search and Replace


slickricky
07-24-2005, 03:03 AM
I'm trying to write this search and replace script using the extended replace option in Macromedia Homesite 5, but I can't seem to get anything to work. I found an example on this forum of a similar replace, but it doesn't work at all either. (I do have the regular expressions box checked too : )

Find: src\=\"([a-z\.]+)\"
Replace: src\=\"/new_path/\1\"

<img src="my_file.png">
to
<img src="/new_path/my_file.png">


What I'm trying to do in the end is replace all instances of the following examples with one expression:


www.mysite.com/somerandomfolder/somerandomfile.html
www.mysite.com/randomfilename.html

with

www.mysite.com/somerandomfolder/somerandomfile.php
www.mysite.com/randomfilename.php


Is this possible? If it can't be done with Homesite, is there another program that will do it?

slickricky
07-24-2005, 03:56 AM
I might not have been entirely clear, so here's exactly what I'm trying to do...

I'm trying to do a search and replace where the beginning is always the same (www.mysite.com), the end is always the same (.html), but the middle changes (some file name like index or index2 or default83), and I need to replace the (.html) with (.php)

Example:

Find: www.mysite.com/randomfilename.html
Replace with: www.mysite.com/randomfilename.php

Ranger56
07-24-2005, 03:58 AM
Open them all...and save them as .php

slickricky
07-24-2005, 04:05 AM
I'm changing links within pages, not the page extensions themselves, thus the search and replace.

Ranger56
07-24-2005, 06:05 AM
View code.


Find:
.html
Change To:
.php

(I can just do ctrl+h to Find and Change, I dont know how to do it in your program though.)

Pepe, the bull
07-24-2005, 06:45 PM
If you have Dreamweaver and have a site defined in it, you can change the name in the files tab on the right and it will automatically update all links referring to that file.

oracleguy
07-25-2005, 05:28 PM
Is this possible? If it can't be done with Homesite, is there another program that will do it?

With regular expressions, anything is possible, lol.

In this instance, what you will need to do is adjust your regular expression so that it makes a submatch with everything before the extension. Now do you actually have domain specified in your links?