Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i have a little question. I have a big html file and want to replace lots of things inside a lot of times. The only problem i cant solve is a replace with a variable.

Example:

<image src="start_files\0002.jpg" style="width:216pt; height:162">

should be transformed in

<a href="start_files\0002.jpg" target="_blank"><image src="start_files\0002.jpg" style="width:216pt; height:162"></a>

do you have an idea how to do it?

I have a windows system with Notepad2 and Notepad++ and i could install a new tool if needed. (like Windows SED). The best solution would be a batch solution where i can add other transformations.

Hope you have got good ideas!

Thanks forward, Fake4d

share|improve this question
add comment

2 Answers

Notepad++ has regular expression search & replace support. You just need to craft a regex to meet your conditions.

share|improve this answer
    
But can i reference parts of the search in the replace? –  Fake4d Mar 23 '12 at 12:47
add comment

You could use a perl script (to use with grep e.g.):

#!/usr/bin/perl
$src='<image src="start_files\\0002.jpg" style="width:216pt; height:162">';
$xp1='(<)';     
$xp2='(image)'; 
$xp3='( )';
$xp4='(src)';
$xp5='(=)';
$xp6='(".*?")';
$xp7='( )';
$xp8='(style)';
$xp9='(=)';
$xp10='(".*?")';
$xp11='(>)';
$xp=$xp1.$xp2.$xp3.$xp4.$xp5.$xp6.$xp7.$xp8.$xp9.$xp10.$xp11;
if ($src =~ m/$xp/is)
{
        $outi="<a href="."$6"." target=\"_blank\"> "."$1$2$3$4$5$6$7$8$9$10$11 \n";
    print $outi;    
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.