Replacing part of hyperlink with the name of the actual file

General discussions about Advanced Find and Replace
Post Reply
matle
Posts: 4
Joined: Mon Jun 04, 2007 9:46 am

Replacing part of hyperlink with the name of the actual file

Post by matle » Mon Jun 04, 2007 10:02 am

Hello Abacre,

let's assume i have a file called
v.html

in this file there exist these hyperlinks:

Code: Select all

<div class="language">
   <b>
   <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>
   </b>
</div>


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.

i.e.
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!

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jun 04, 2007 10:38 am

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:
\r\n$2$1$3

That's all I verified it works perfectly.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

matle
Posts: 4
Joined: Mon Jun 04, 2007 9:46 am

Post by matle » Mon Jun 04, 2007 12:23 pm

Thank you very much ,

it looks like this solution is almost perfect!

It worked for all files with one letter in the beginning
f.e.
g.html
y.html
b.html

But how must the RegExp or AFR-options be changed to fit files like:
v-kita.html
b-impressum.html
?

Thank you again in advance for your help!

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jun 04, 2007 12:32 pm

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:
[\w\-]
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

matle
Posts: 4
Joined: Mon Jun 04, 2007 9:46 am

Post by matle » Mon Jun 04, 2007 12:39 pm

So the exact search string looks like this: ?
.*\\(\w\-)\.html\r\n(.*<a href="\.\./eng/)(\.html" class="lang">ENGLISH</a>)

It returned 0 findings :-/

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jun 04, 2007 12:44 pm

The resulting Search For should be:

.*\\([\w\-]+)\.html\r\n(.*<a href="\.\./eng/)(\.html" class="lang">ENGLISH</a>)
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

matle
Posts: 4
Joined: Mon Jun 04, 2007 9:46 am

Post by matle » Mon Jun 04, 2007 12:57 pm

Perfect!
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

matle

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest