find and replace between http:// and ]

Find, replace, find in files, replace in files, regular expressions

find and replace between http:// and ]

Postby filosofo » Fri Aug 10, 2007 2:41 am

Hi everyone!

I really love UltraEdit, because I'm changing my wikisite from Schtuff to Wikidot. Everything has been perfect, except that I don't know how to do two things. I will be really gratefull if anyone can help me with this:

I have to modify the / character in every external link, so I need to know how I can search for all the / characters that are between http:// and ] . The sintaxis in the txt file is one like this:

[http://page.com/sub1/sub2/etc]

The problem is that the number of / vary for every link I have in aprox 990 files. I need to replace the / for a & or any other symbol that let me protect them from the conversion of / to //, which is the Italic format conversion from one wiki to another.

I'm using the latest version (v131.10a+1) of UltraEdit.

Thank you
User avatar
filosofo
Newbie
 
Posts: 2
Joined: Wed Aug 08, 2007 11:00 pm

Re: find and replace between http:// and ]

Postby pietzcker » Fri Aug 10, 2007 8:24 am

Hm, well, this is a problem. The quick-and-dirty solution I can come up with doesn't work with UE because the Perl regex engine can only handle fixed-length lookaround.

Code: Select all
(?<=\[http:.*)/(?=.*\])
works with tools like RegexBuddy but not with Perl and therefore not with UE. (Even if Perl allowed for variable-sized lookaround, it wouldn't work because UE's implementation of positive lookaround is buggy, so you could find the string but not replace it).

If you are fluent in a .NET language you could use this regex in a small program that could then replace those matches.

JavaScript doesn't support lookbehind at all, but maybe someone could write a (UE) script that checks the slashes "manually". This will be a lot slower than using regexes but has a bigger chance of working. Do you have Python? Python's regex engine has the same limitations as Perl, but I could write a script that does the job pretty quickly.

Maybe there is a different solution I haven't thought of yet.

I'll post again if I have another idea...
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: find and replace between http:// and ]

Postby pietzcker » Fri Aug 10, 2007 8:47 am

What you can do is search for
Code: Select all
(\[http:.*?)/(.*\])
and replace with
Code: Select all
\1&\2

This will replace one "/" per line by "&" if the "/" is between "[http:" and "]". So you need to run this replace at least as many times per file as the highest number of slashes that there is on any line.

This will be cumbersome and slow (lookaround would be a lot faster), but at least it works.

Or you could download the trial version of RegexBuddy and use the regex in the post above on your files. See http://www.regexbuddy.com/download.html

HTH,
Tim
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: find and replace between http:// and ]

Postby Mofi » Fri Aug 10, 2007 9:05 am

pietzcker wrote:This will replace one "/" per line by "&" if the "/" is between "[http:" and "]". So you need to run this replace at least as many times per file as the highest number of slashes that there is on any line.

Excellent idea!

If you want to use the UltraEdit regular expression engine, open Replace In Files, search for regular expression ^(^[http:[~/^]]++^)/ and replace it with ^1&.

Run this replace in files until you get the message "0 items replaced in 0 files".

But first test this regular expression replace with normal Replace command on a single file !!!
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: find and replace between http:// and ]

Postby filosofo » Sat Aug 11, 2007 2:54 am

I just want to thank you both, pietzcker and mofi, for helping me. The solution was incredible!!!!
You're great!!!! :D
User avatar
filosofo
Newbie
 
Posts: 2
Joined: Wed Aug 08, 2007 11:00 pm


Return to Find/Replace/Regular Expressions