PDA

View Full Version : search and replace


jbroder
12-31-1998, 03:09 AM
I am using Allaire homesite, which allows
editing pages with regular expressions (regex).

Regex looks a lot like sed expressions, so I knew enough to write this expression to find all links in my pages to .wav files called july23.wav and aug13.wav and so forth.

[a-z]*[a-z][a-z][a-z,0-9][a-z,0-9][a-z,0-9]\.wav

What I wanted to do is put all the wav files
in a separate directory.When I went to change all the references to http://www.guitartricks.com/sound/[a-z]*[a-z][a-z][a-z,0-9][a-z,0-9][a-z,0-9]\.wav

instead of giving me back the orinal file names, it just named all the files
[a-z]*[a-z][a-z][a-z,0-9][a-z,0-9][a-z,0-9]\.wav

oops!

What is the right way to express the idea
that all the text that now reads "filename.wav" needs to be directed to
"sound/filename.wav" from now on?

Thanks!

Terra
12-31-1998, 09:08 AM
hmmm, Looks like the damage has already been done...

I am not very familiar with Homesite or sed, but my forte is perl... I would have written the regex something -quick-n-dirty- like this

$path =~ s#(http://www.guitartricks.com)/(\w+\.wav)$#$1/sound/$2#;

Regex's are an awesome tool, that sometimes can really give you a major brain cramp, due to it's atomic methods...

I'm not sure if the above helps you any, it's just a different way of doing the regex... It also depends if HomeSite uses the DFA or NFA regex engine - as Perl uses NFA...

If you are really interested in learning regular expressions, I highly recommend the book 'Mastering Regular Expressions' published by O'Reilly...
ISBN: 1-56592-257-3

--
Terra
sysAdmin
FutureQuest


------------------
www.FutureQuest.net (http://www.FutureQuest.net)
--FutureQuest goal: (10x+8)/(x+1)=9.99--
--The best way to predict the future is by inventing it--

jbroder
01-01-1999, 08:32 PM
I posted this question to the allaire forum and got the answer. Here it is in case anyone is interested. I believe it would apply in sed as well.

They said to put the search expression in parentheses and then refer back to it with a '\1' (without the single quotes). If I had two sets of parenthesis the second would be '\2' and so on. This is called "backreferencing."

Here is the expression that worked:

([a-z]*[a-z][a-z][a-z,0-9][a-z,0-9][a-z,0-9])\.wav

# replace with

http://www.guitartricks.com/sounds/\1.wav

Thanks for the perl tip. I am starting to try to figure that out too.

Jon

------------------
guitartricks.com