find and replace between http:// and ]

find and replace between http:// and ]

2
NewbieNewbie
2

    Aug 10, 2007#1

    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

    236
    MasterMaster
    236

      Aug 10, 2007#2

      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...

        Aug 10, 2007#3

        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

        6,675585
        Grand MasterGrand Master
        6,675585

          Aug 10, 2007#4

          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 !!!
          Best regards from an UC/UE/UES for Windows user from Austria

          2
          NewbieNewbie
          2

            Aug 11, 2007#5

            I just want to thank you both, pietzcker and mofi, for helping me. The solution was incredible!!!!
            You're great!!!! :D