Using RENAME with REGEXP

I've been at this for hours, and I just can't get this figured out.

I have a regex I'd like to use in a button script. I have the regex working in the RENAME GUI tool; I just can't figure out the syntax for the button script.

Here is my attempt:

rename REGEXP PATTERN="(.) (..).xxx" FROM ".xxx" TO "\1.xxx"

Something much be wrong with the syntax ... ANY help would be VERY much appreciated.

Hello,
This is almost certainly solvable.
I see several problems with your syntax though.
Could you post an example of a rename you wish to accomplish?

As a first step get rid of the From clause.
A second step is to look at your usage of the '' character .
This character escapes the normal RegExp usage of the character that immediately follows it.
In other words, if you want to specify the actual '' character, you need to preceed \ with .
The actual character '' is specified by \ .

I'm not at all certain yet what you are attempting here.

Can you also tell us what that code is ?

Let us know !
I do think this easily solvable.

Regards,
Zippo

Alright ...

I'm looking to remove something from a filename.

foo (fo).xxx

I want to rename to:

foo.xxx

As you can see by the attached picture, I have successfully done this via the rename tool. (Note: I want ANY two chars between the parens to be removed).

Now, I just want to duplicate it in script.

Thank you!!


Hi,
You almost have it.

How about

Rename REGEXP PATTERN="(.*)(\(..\))(\.xxx)" TO="\1\3"

Of course there are several solutions to this problem.
I thought this was a good place to start.
The quotes will help if there happen to be space characters in the filename.
I really haven't tested it though.

Zippo

Ooops,
Looks like I missed a space character in there.
Sorry.

Rename REGEXP PATTERN="(.*)( \(..\))(\.xxx)" TO="\1\3"

Zippo

It didn't initially work as I had hoped (that script only works on SELECTED files - which didn't work out for my needs) - but the syntax you provided got me through the hard times :slight_smile:

My final solution: (for anyone else that might be trying to accomplish the same thing)

Rename REGEXP PATTERN="(.) (..).xxx" TO="\1.xxx" FROM=".xxx"

... This performed what I needed. I added the FROM= to allow it to work on unselected files.

Thanks a bunch guys ... you never fail me! :slight_smile:

Hmmm...
I didn't know it.
I would have just selected all files and run my solution.

I'm glad you have it now though.
Isn't it just amazing what you can learn here?

Zippo

It is ...

It's even MORE amazing that 99.9% of anything I want to do with files can be done one way or another with Dopus ...