Is it possible to do a regex find and replace on just a part of the name?

Dumb question maybe
But right now the only way I know, within Opus, is to define a regex from start to end.
I don't know a way to use regex for just replacing a -part- of the filename.

For example, I need to remove a specific part from the filename (same part is mentioned twice in the same filename).
In the below screenshot I need to replace : -Part1[-\s]dtd
with just a space.

Another renamer can do that, within Opus I need to do something like:
find: ^(.+)(-Part1[-\s]dtd)(.+)
repl: \1\3

Maybe I am overlooking something, maybe Opus works this way as it is.

no need to use regex.
use the search and replace mode, and type in part and the replacement string.

regex in this example gives me some flexibiliy to replace 'part1 ' and 'part1-'
i.e. followed by a space or a '-'

I don't think what you are asking is possible. Though I do agree it would useful at times.
Currently when using regexp you need to match and replace the whole name. So as you have said you can achieve what is needed, you just need to match the whole word and then use the \1\3 style output.

I might be easier in some circumstances (esp depending on you regexp skill level) to have a regexp version of find and replace.

Thanks.
Obviously the above example is a very simple one, to illustrate the idea.
I did have these 'partial' regex find/replaces on regular basis in the past, but never took the time to ask here. I just went on, assuming that I am lacking regex knowledge. Well, maybe one day it will be possible. Anyway, thanks again.

It's not clear what you want. I'm sure it can be done here, especially with the advanced scripting functionality. If you explain your requirements better, maybe someone can help.

So far, I understood, you want to replace only 1 instance of part that occurs in a filename if there are multiple instances.
The example screenshot suggests this.
if you could give a before & after list of filenames, that would help in testing out different regexes

Thanks for getting back on this.
However, please consider the matter as 'solved': what I want isn't yet possible within Opus.
(also see reply from wowbagger)

You are right I can be done in a script. What @opw62 is asking can be done with regexp, he even included the regexp in his post.

But what he is requesting is a simpler solution, or a shorter way of writing it. DOpus requires your regexp match the whole string. Another approach is to match within the string and replace just the part that matched.

Essentially its a find and replace where the find is a regexp and you don't need to match on the whole string.

So you might say find: \d{4}[-\s]\d{2}[-\s]\d{2} replace: .
In DOpus you would find: ^(.*?)\d{4}[-\s]\d{2}[-\s]\d{2}(.*)$ replace: \1 \2.

This is pretty common in text editors where you might find any/many instances of a regexp and replace it with something else. Its less needed in DOpus as you are usually looking for one instance to match on, as a filename is not so long..

1 Like

Thanks for the clear explanation, now it makes sense, and you are right, I've encountered the same issue, but it has usually been worked around using the solution you mentioned. Never thought of improving it, but it's a good suggestion for improvement especially if it's how other renamers work as it would be consistent across them.

I would think you could replicate the same functionality with a script that takes a regex as input and applies it using the global/multiline syntax. I don't know if that would work with previews though.

We'll add this ability in the next update.

1 Like

Super! Thanks.

Wonderful!

Many thanks indeed!

//
v12.7.3
The Rename tool has a new mode, Regular Expressions + Find And Replace, which combines both modes (lets you search and replace within filenames using regular expressions, without having to construct a pattern to match the whole name).
//

Q:
Will "Regular Expressions - find and replace" also support the " ^ " (start of line anchor) ?

Example:
find: ^(\d{4})[.,-\s\s?]
repl: \1 (following by a space)

fm: 2018,blabla text 1743. blabla.png
to: 2018 blabla text 1743. blabla.png

the regex will also consider 1743.
(Yes, I know - I can avoid this by adding (.+) and \2)

I expect it does. Did you try it and find it didn't?

I am not sure it does...
However, it is better 'ask' than 'stating': I've learned here to refrain from stating that Opus does nót do something as usually it was me making some mistake, forgot something or should have done some more research before asking... :slight_smile:

note the fullstop after 1743 in the below example

The whole point of the find & replace mode is that the match can occur anywhere, any number of times, within the string. If you want it anchored to the start then you may as well just use the original mode.

Okay, thanks.

We'll make $ and ^ work in this mode in a future update. It won't be in 12.8 but should be in 12.8.1 after that.

1 Like

That is great, Leo. Many thanks.

Reason for asking/suggesting this is that, right now, for the use the ' ^ ' anchor, I needed to load the file names into a 3rd party renamer. Should it not be too complex to implement, then maybe it would be reasonable to add this to Opus.