Page 1 of 1

Replacing part of hyperlink with the name of the actual file

Posted: Mon Jun 04, 2007 10:02 am
by matle
Hello Abacre,

let's assume i have a file called

in this file there exist these hyperlinks:

Code: Select all

<div class="language">
   <a href="../v.html" class="lang">DEUTSCH</a> -
   <a href="../pol/v.html" class="lang">POLSKI</a> -
   <a href="../eng/.html" class="lang">ENGLISH</a> -
   <a href="../fra/v.html" class="lang">FRAN&Ccedil;AIS</a> -
   <span class="actlang">ESPA&Ntilde;OL</span> -
   <a href="../rus/v.html" class="lang">РУССКИЙ</a>

Now as you can see, the link for the ENGLISH version is only linked to ".html",

Can i use AFR to replace the string "/eng/.html" to "/eng/[FILENAME_WHERE_THAT_STRING_HAS_BEEN_FOUND_INSIDE]" in Batch replace, because i have around 150 files where theres is the case.

File v.html: "/eng/.html" -> "/eng/v.html"
File v-blah.html: "/eng/.html" -> "/eng/v-blah.html"
etc. etc.

Thank you for your help!

Posted: Mon Jun 04, 2007 10:38 am
by Abacre
At least two solutions are possible:
1. You can take file name from surrounding text, for example, from
<a href="../pol/v.html" class="lang">POLSKI</a>

2. You can take file name directly from name of the file.

The the second solution:

Go to main menu - Action - Options - Batch Replace
check "Modifier S"
check "Include File Name into Search Scope"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
.*\\(\w+)\.html\r\n(.*<a href="\.\./eng/)(\.html" class="lang">ENGLISH</a>)

Replace with:

That's all I verified it works perfectly.

Posted: Mon Jun 04, 2007 12:23 pm
by matle
Thank you very much ,

it looks like this solution is almost perfect!

It worked for all files with one letter in the beginning

But how must the RegExp or AFR-options be changed to fit files like:

Thank you again in advance for your help!

Posted: Mon Jun 04, 2007 12:32 pm
by Abacre
This is because of \w which means "alpha-numeric" char: 0..9 a..z A..Z
If you want to use - char then instead of \w you should use:

Posted: Mon Jun 04, 2007 12:39 pm
by matle
So the exact search string looks like this: ?
.*\\(\w\-)\.html\r\n(.*<a href="\.\./eng/)(\.html" class="lang">ENGLISH</a>)

It returned 0 findings :-/

Posted: Mon Jun 04, 2007 12:44 pm
by Abacre
The resulting Search For should be:

.*\\([\w\-]+)\.html\r\n(.*<a href="\.\./eng/)(\.html" class="lang">ENGLISH</a>)

Posted: Mon Jun 04, 2007 12:57 pm
by matle
thank you again very very much Mr. Vasin for your fast and very accurate help, which saved me from hours of stupid copy&paste work.

I've never worked with RE before, but it is definitely an exciting field of Computer Science!

Best Regards