Topic: Regular expression

Hi,

I have files whose names are

yyyy-mm-dd.something.else.ext

I would like to put the front date at the end of the base file:

something.else.yyyy-mm-dd.ext

The regular expression

%b(s/(.*?)\.(.*)/\2/)

gives

something.else

as expected, but

%b(s/(.*?)\.(.*)/\1/)

gives

yyyy-mm-ddsomething.else

instead of

yyyy-mm-dd

Furthermore, \2 could be replaced with \3, \4, etc.: I think that those variables values should be empty instead of giving the same value of \2.

Did I discover a bug?

Regards,
Michel.

Re: Regular expression

Hello Michel,

I am not a regular expression specialist but looking at what you wanted to do I noticed that you didn't set any "anchor" : ^ or $.

All looks fine when you change your expression to :

%b(s/^(.*?)\.(.*)$/\2/)

Maybe this could be related to "wxRegexp" regular expression implementation or to the parameters set by Siren when using them.

You can find details there.
Note that Siren uses the advanced regular expressions (ARE) implementation (wxRE_ADVANCED).

Regards

Remi

Re: Regular expression

Right, since Siren can handle (work with) parts of file name only,

you have to use the correct anchors to get what you want to achieve:

%b(s/^(.+?)\.(.+)$/\1/)
%b(s/^(.+?)\.(.+)$/\2/)


Use ^...$ to tell the engine to match from begin till end of the origin string (file name).


- - -

FROM:
yyyy-mm-dd.something.else.ext
TO:
something.else.yyyy-mm-dd.ext
USE:
%b(s/^(.+?)\.(.+)$/\2.\1/).%e


- - -

Also I use the '+' multiplier here, instead of the '*' one,
since I think you want one-or-more instead of nothing-or-more.

- - -

To work only on files starting with an date like yyyy-mm-dd, better use
%b(s/^(\d{4}-\d{2}-\d{2})\.(.+)$/\2.\1/).%e
That way you can select many files and only the one starting with an date are renamed.



HTH?

- - -

And Michel, please use a more meaningful Topic next time, so everybody can better find what he is searching for. Thank you.
Topic: Regular expression
Topic: Regular expression gives me wrong result on switching parts