|
From: Zurd <zu...@ya...> - 2007-02-22 04:16:03
|
> I didn't found anything useful. The last thing I tought, was to install KRename
> and see if it works in their software, if it does, then I'll have a look at
> their code and see if I can implement the same thing in GPRename.
>
> Else I will post a note in Help/Tips that backreferences in Replace/Remove
> cannot be use.
So as I said, I've checked out KRename and using backreferences in it doesn't work.
See screenshot attached.
I also tried a simple perl script to try to make it work in another way :
$file='abc5.txt';
$replace = 's/([0-9])/$1/g';
$file =~ $replace;
print $file . "\n";
But even this won't work! Bottom line : You just can't use it in a script as
$1 gets confused with a perl variable. Too bad, but since there's more than 1
way to rename files, I don't see it as a problem :-)
I'll add a note in the Tips section that backreferences cannot be used.
--- Zurd <zu...@ya...> a écrit :
> > Ooups ... your reply as been "junked" by my mail client
> > I was thinking that my question was so stupid that it didn't worth
> > answering ;-)
>
> Not at all, your question is actually one of the most "head scratching" I've
> got since I first started coding GPRename !
>
> Thanks for the clarification and the examples, I've searched a lot the internet
> for information on this and I've learned what is "backreferences" in Perl
> Regular Expression.
>
> Now, here's a little perl script that I've made, if you copy that in a text file
> and call it by "perl file" it will produce the result "x = 7"
> It's really quite simple, if it match a digit, here the number 7, then print this
> number, and it do. Backreference works perfectly well here.
> $x = "7";
> $x =~ s/([0-9])/$1/g;
> print "x = $x\n";
>
> Now another example, the same thing, but this one's not working. It will print
> "a =", not printing the number 7 :
> $a = "7";
> $b = "$1";
> $a =~ s/([0-9])/$b/g;
> print "a = $a\n";
>
> After much research, it looks like that $1 from $b is treated as an empty
> variable, so it doesn't print anything. But if you call $b = '$1';
> (single quote instead of double quotes), it's going to treat $1 completely
> as a string and print the string '$1', not a backreference, which is what
> GPRename is doing, unfortunately.
>
> Here's the GPRename code doing this :
> $new_name =~ s/$replace_this/$replace_with/g;
> It's a simple Perl Regular Expression using Substitution, which is exactly
> the same as the first example, which shoud work the way we want it to,
> not much I can change here.
>
> Someone on #perl on IRC gave me this trick which works :
> $g = "7";
> $h = "1";
> $g =~ s/([0-9])/$$h/g;
> print "g = $g\n";
> It sure looks strange and is not a standard, but in a shell script, it works!
> In GPRename, it doesn't work, it says :
> Can't use string ("1") as a SCALAR ref while "strict refs"
> Whatever, that way is not clean and useful, so let's not bother with this.
>
> And now I'm almost out of idea on what to do. I've searched the web a lot and
> I didn't found anything useful. The last thing I tought, was to install KRename
> and see if it works in their software, if it does, then I'll have a look at
> their code and see if I can implement the same thing in GPRename.
>
> Else I will post a note in Help/Tips that backreferences in Replace/Remove
> cannot be use.
>
> As for your files, since you said there's another way to rename them, well go
> ahead, for now it's the best way to deal with them :-)
>
> And actually, I'd say there's always another way to rename files without
> backreferences, so it's not a big loss if I can't implement it ;-)
>
>
>
>
> > > --- Hippo31 <hi...@fr...> a écrit :
> > Actually i want to modify filenames by reusing some part of the original
> > one, example:
> > DBZ - 277 Prochaine victime la Terre HQ-FR-Jaxx21.avi
> > replace with
> > DBZ 277 - Prochaine victime la Terre HQ-FR-Jaxx21.avi
> >
> > Backreferences are extremely useful in this case (even if this is not
> > the only way to do it).
> > With sed it could be made like this:
> > echo "DBZ - 277 Prochaine victime la Terre HQ-FR-Jaxx21.avi" | sed 's/-
> > \([0-9][0-9][0-9]\)/\1 -/'
> > As you can see i have put the group of tree digits in the search pattern
> > between (necessary escaped) brackets which places it in the first
> > "pattern space". I call it back in the replace pattern using the \1
> > special key
> > Of course perl allows this kind of substitute constructions and even
> > simpler !
> > filename = s/- (\d+)/$1 -/;
> > Which could be translated in full word in: "REPLACE a minus followed by
> > a space followed by (being of the pattern space) one digit (\d) or more
> > (+) (end of the pattern space) BY 1st pattern space followed by a space
> > followed a minus"
> >
> > To come back with gprename when i try this kind of substitution i get
> > DBZ $1 - Prochaine victime la Terre HQ-FR-Jaxx21.avi
> > so ... no call back of the pattern space.
>
>
>
> > Zurd a écrit :
> > > Well, I'm not an expert on perl regular expression and your command almost
> > > looks cryptic to me ;-)
> > >
> > > As I understand, you want to switch the "- " to the end of the filename?
> > >
> > > If you could provide me with a few filenames examples I'll be able to better grasp
> > > what you're trying to achieve.
> > >
> > > What I'm sure of though, is that if you use the Perl Regular Expression checkbox,
> > > the replace/with becomes a normal substitute regular expression like
> > > sed 's/replace_this_field/with_this_field/g'
>
>
> > > --- Hippo31 <hi...@fr...> a écrit :
> > >
> > >> Hello,
> > >> I recently discorered this nice tool and feel it quite useful, but i
> > >> would like to make a replacement like this "s!- (\d+)!\1 -!"
> > >> Through gprename i have tried
> > >> Replace "- (\d+)" with "\1 -"
> > >> and also
> > >> Replace "- (\d+)" with "$1 -"
> > >>
> > >> but the displayed result doesn't look like what i was expected
> > >>
> > >> Isn't there possible to use the backreferences in the target space ?
> > >>
> > >> Hippo31
__________________________________________________
Do You Yahoo!?
En finir avec le spam? Yahoo! Courriel vous offre la meilleure protection possible contre les messages non nollicités
http://mail.yahoo.ca Yahoo! Courriel |