I have several files to rename. I will rename them using a batch renamer software. It can remove patterns using regular expression. Here are two file name examples:
13 (a 3f kd) kjhucj 1 _ m (52 min) - jrhkfq 324
647 fjk3 d [63h hh] _ (jhgbh) abim (238 min)
I want to remove all characters after _\s
but keep the \(\d+\smin\)
part. I want them to be renamed to:
13 (a 3f kd) kjhucj 1 (52 min)
647 fjk3 d [63h hh] (238 min)
I tried _\s.*[^(\(\d+\smin\))]
but got weird results. I don't know if this is even possible.
What you're really trying to do is remove everything between _\s
and (
, as well as everything after )
. Alternatively, you want to keep everything up to _\s
, and between (
and )
. You should aim to define the delimiters of your capture groups rather than the contents most of the time:
(.+?)_\s.*(\(\d+ min\)).*
In this case, instead of removing, keep the contents of capture groups 1 and 2 only. Many tools will allow you to say something like \1\2
in the replacement pattern.
If your tool removes an entire match and you insist on doing it like that, you will have to use a two pass approach, since you have two disconnected regions to remove. This would require a tool that supports lookahead and lookbehind, as most of them do.
The first pass would use
_\s.*(?=\(\d+ min\))
The second pass would remove
(?<=\(\d+ min\)).*