I'm going to be sorting through a large mass of html files and replacing links to an ftp site with local links. I am using vim and I am trying to figure out a pattern to use with
%s/find/replace/g that will match a string such as
and replace it with
essentially replacing everything except the file name itself. There will be multiple ftp directories in a single html file so the pattern should be able to match any type of ftp link. All of these ftp files will be going into the same local directory. Although most of the files are pdfs some are ptts and other random files.
Are Vim's patterns able to match something like this, and if so what would that pattern look like?
@akira did a great job with the regex supplied in his answer. I went out on my own to find a way to put this into a reusable function and this is what I came up with:
(inside your vimrc) define a function that allows you to pass a string to replace the matched string
function SwitchFtp(local) execute ':%s,href="ftp://.*/\(.\+\)",href="'.a:local.'\1",g' endfunction
(optional) assign this function to a command so that you don't have to use
command -nargs=1 SwitchFtp call SwitchFtp(<f-args>)
This would then be called with something like