Pattern/Regexp Help

Does someone know how to do these 2 things in either Pattern or Regexp?

  1. Rename PATTERN="sometext" TO="" FINDREP
    So it removes sometext no matter where in filename it exists but doesn't replace it with anything.

  2. Take this filename,
    some-text- some - text -sometext.ext.
    So it changes every "-" to " - " but doesn't add extra spaces and make like " - " so there's just 1 space on either side of every -


You could do this with a regular expression, but I'd use the standard DOpus rename tool instead. Select the file names you want to process, then click on FILE/FILE COMMANDS/RENAME and put it in FIND AND REPLACE mode.

Next in the OLD NAME box put a single space and leave the new name box blank. Press OK and all the spaces in the selected file names should be stripped out. Select the names again, launch the RENAME dialog box again and put it in FIND AND REPLACE mode again.

This time in the old name box put just a -

And in the new name box put SPACE-SPACE

where each SPACE represents an actual space. Press ok to insert one space on each side of each -

Hi, Thanks for reply.

Well 2 things. First is that i want these to be buttons and second thing is, the filename may have spaces in other locations so i don't want to strip out all spaces.

Curiously enough there appears to be a few bugs with the RENAME FINDREP command/argument when it's used in a toolbar button.

For one thing it doesn't seem to accept a null value as a replacement value unlike the rename dialog box find/replace operation.

Then I created a couple rename presets, saved them, and tried to call them from a toolbar button command like this:

Rename PRESET="Strip Spaces"

And it either outright fails or gives improper results.

A RegExp would require a specific pattern in order to do the job and since you have spaces in other areas of the file names that you don't want changed, it doesn't look like a regular expression is the answer here either.

So to me at the moment anyway, a toolbar button to do this doesn't look practical. Perhaps someone else has some insight on something I'm missing.

First one:

Rename REGEXP PATTERN "^(.)sometext(.)$#" TO "\1\2"

The second one you can also do using a regular expression. It took a bit of thought but this seems to work:

Rename REGEXP PATTERN "^(.+)([^ ])( -|- |-)([^ ])(.+)$#" TO "\1\2 - \4\5"


From: ^(.+)([^ ])( -|- |-)([^ ])(.+)$#

To: \1\2 - \4\5

In both cases the begining ^ and end $ are probably not needed, but they don't hurt either.

Hey nudel,

Thanks very much. They working and i understand regexp a little better but have much to learn :slight_smile:

Yup, I figured I was missing something, I'd forgotten about the new # repeat option for RegEx.

Thanks for the example, Leo. I firmly believe that if the manual had more examples that there'd be less questions on here.