Topic: How to get rid of expr3

Hi.

I'd like to get rid of expr3 (stuff between brackets only).

The following type of files are affected:

"expr1 (expr3).ext" should become "expr1 ().ext"
"expr1 (expr2) (expr3).ext" should become "expr1 (expr2) ().ext"

The problem is the 2 different kind of files (expr2).

How can I tell Siren to delete expr3?

Thanks,

Re: How to get rid of expr3

Is it possible that this is the solution?

%b[-2,"("] ().%e

Thanks,

Bye,

3 (edited by geohei 2007-09-16 12:01:28)

Re: How to get rid of expr3

In fact, I forgot one file type ...

"expr1 (expr3).ext" should become "expr1 ().ext"
"expr1 (expr2) (expr3).ext" should become "expr1 (expr2) ().ext"
"expr1 (expr3)[1].ext" should become "expr1 ()[1].ext"
"expr1 (expr2) (expr3)[1].ext" should become "expr1 (expr2) ()[1].ext"

Sorry, but I can't get this [1] to remain sad

Any ideas?

Thanks,

4 (edited by Stefan 2007-09-17 00:02:56)

Re: How to get rid of expr3

Hi Georges,
i guess your "expr3" is not always the same chars? Would be to simple.

The trick is to find something what is common with all this different file names,
if we didn't find something common we have to first separate the files we need or do it in several passes.

But i see one common thing: (expr3) is always at the end of the file name....right?

So we search for:
The base file name:              %b
start an regEx:                    (s/
all in front:                         (.+)               Group () 1
but no opening bracket (:    [^\(]              not needed here! ... don't know why!
till an opening bracket (:     (\()                Group () 2
all:                                   .+                  an another group, what we need not longer so we didn't use ( and ) here
till an closing bracket:         (\))                Group () 3
the rest if any:                   (.*)                Group () 4
end the regEx search:         /
do the replacement:           \1\2\3\4          replace whit what we have found with Group 1, Group 2,...
end the regEx:                  /)
add an dot and the ext:     .%e       

So i would do with Siren 2.0
Expression: %b(s/(.+)(\().+(\))(.*)/\1\2\3\4/).%e


HTH? :-)
What is that with those [1] thinggies? I didn't understood. You want them or not?

And you didn't mentioned
"expr1 (expr2).ext"
and
"expr1 (expr2) [1].ext"

this would also be affected and deleted with my RegEx.

I guess you have to put your files you want to rename apart first?
Or rename your  "expr1 (expr2).ext"  first to e.g. "expr1 [expr2].ext"  and later back.
It's hard to guess without you provide some real  file names. (If you do this make an list with one name at an row only, and without comments or quotes please, so i can copy them at easy and create files with this names. See http://scarabee.software.free.fr/forum/ … hp?id=187)

Re: How to get rid of expr3

Edit:
> not needed here! ... don't know why!

Surely i KNOW why ;-)

we search for an opening bracket:                      (
followed by one or more chars or signs:              .+
followed by an closing bracket:                           )
followed by none or one or more chars or signs:  .*
followed by the end of the file name:                   .%e

is pretty accurate i guess ;-)

Re: How to get rid of expr3

Hello,

I will suppose that the modification needed consists to remove the content of the last "()".

The "nicest" solution seems to be the regular expression. Here is one based on the same principle as Stefan's one:
%f(s/(.*\().*(\).*)/$1$2/)

If you want to use a "standard" expression, this heavy one should work:
%f("(",".*",-1)(")","*.",-1);%f[1,"*"](1,-1)\(\)%f[3,"*"](2)

It uses sub-expressions (only available since version 2.00).
The idea is near the same as the one explained in an example accessible though Siren's "?" menu.
A '.' is added to the '*' to keep the spaces before and after the "()".

7 (edited by geohei 2007-09-17 19:57:11)

Re: How to get rid of expr3

Hi guys.

THANKS A LOT!

The shortest version was the one from Rémi.

%f(s/(.*\().*(\).*)/$1$2/)

It worked perfectly.

However the bottomline for me was also to understand what happend here! Thanks to the explanations of Stefan, I managed to get it more or less.

%f(s/(.*\().*(\).*)/$1$2/)

(.*\() - variable $1 - everything until last opening bracket (including this).
.* - delete everything after until ...
(\).*) - variable $2 - ... next bracket - include this bracket and everything right of it.

Is this correct?
This is tricky stuff!

BTW ... The Siren Help (F1) doesn't explain regular expression (all which comes after "s/"). Where do you get these "commands" from (à la (.*), (.+), ...)?

What is that with those [1] thinggies? I didn't understood. You want them or not?

Yes, I do need them.

Many thanks again. Great job, and powerful software!

Bye,

Re: How to get rid of expr3

geohei wrote:

Is this correct?

Yes, it is.
(Stefan's explanations were very clear, thanks to him)

geohei wrote:

BTW ... The Siren Help (F1) doesn't explain regular expression (all which comes after "s/"). Where do you get these "commands" from (à la (.*), (.+), ...)?

As Siren uses Boost's regular expression code I've preferred to redirect the users to their URLs:
For the format string (part between the first and second '/'), look here
For the replacement string (part between the second and third '/'), look here
For a more "general" help, look here

Regular expressions are widely used. I encourage you to have a look at them.

Re: How to get rid of expr3

Ok. Thanks a lot (again)!