complex replace

Advanced Renamer forum
#1 : 01/05-19 10:35
Ed M.
Ed M.
Posts: 2
In the example below...each section could have spaces etc

Example:
original = section1 - section2 (section3).txt
result = section1 - section3.txt

I want to remove section2 altogether. I also want to remove the parenthesis.

Please help.

Ed




01/05-19 10:35
#2 : 01/05-19 10:56
Ed M.
Ed M.
Posts: 2
Reply to #1:
Looks like I was able to read other forum messages and figured out how to solve my own problem.

replace (.*) - (.*)\((.*)\)
with \1 - \3

Thank you everyone for all the helpful messages in this forum.

Ed


01/05-19 10:56
#3 : 01/05-19 16:42
David Lee
David Lee
Posts: 217
Reply to #2:
Just for fun (and because I've recently discovered the \K meta-character!)...
you can match all the unwanted segments with a single RegEx:

replace (.*) - \K.* \(|\)
with nothing

\K is particularly handy since "lookbehinds" are not available in this flavour of PCRE

Basically everything prior to \K is deleted from the final match


01/05-19 16:42 - edited 01/05-19 17:21