It has been a while for me with regex...

A swapping-ground for Regular Expression syntax

It has been a while for me with regex...

Postby JCN9801 » Mon Aug 12, 2019 11:12 pm

More than 20 years since I played in Unix...

Can I get a hint on how to bulk remove a filename suffix ending in -d -dd -ddd where the d=[0-9] digits. Example: MyVideo-01.mp4 to MyVideo.mp4

Also I would like to be able to reverse a suffix pattern: Specifically <filename>(tr)([A-Z][A-Z]).mp4 to be <filename>([A-Z][A-Z])(tr).mp4
without individually going through all of the [A-Z] patterns (about a dozen of them, e.g., MA, MB, LV, LR, LP, etc).

Finally Is there a way to filter for filenames that DO NOT contain a specific string: E.g., *(SCL-* all files NOT containing "(SCL-"

Thanks for helping a retired tech geezer,
---Jeff :D
JCN9801
 
Posts: 5
Joined: Mon Aug 12, 2019 10:52 pm

Re: It has been a while for me with regex...

Postby therube » Tue Aug 13, 2019 4:49 pm

1:RegEx
Code: Select all
Match:  (.*)(-\d{1,3})$
Replace:  \1


See if that will do what you need.
Match everything up to the first "-digit{1 to 3 times}".

---

Everything
Search: !SCL(

Then drag the files into BRU.

---

Better examples of your reverse issue?
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: It has been a while for me with regex...

Postby JCN9801 » Thu Aug 22, 2019 5:35 pm

Thanks so much for the hints!

Better example of desired pattern reversal: MyVideo(tr)(MA).mp4 to MyVideo(MA)(tr).mp4

W.R.R. with (MB), (LR), (LV), etc...

Regard and thanks,
---JCN
JCN9801
 
Posts: 5
Joined: Mon Aug 12, 2019 10:52 pm

Re: It has been a while for me with regex...

Postby JCN9801 » Tue Aug 27, 2019 12:48 am

I tried the regex match suggested to achieve MyVideoFile-1.mp4 --> MyVideoFile.mp4
I got no matches.

Anyway, I need the match to be at the very end of the file, aka stripping the -1, -29, -101 off (as a suffix).

Oh, in my case it could be matching (tr)-1 to (tr) : MyVideoFile(tr)-1.mp4 --> MyVideoFile(tr).mp4 since the (tr) is always present at the end of the filename.

Thanks again!
---JCN
JCN9801
 
Posts: 5
Joined: Mon Aug 12, 2019 10:52 pm

Re: It has been a while for me with regex...

Postby therube » Thu Aug 29, 2019 4:35 pm

With MyVideo-01.mp4.

I get:

photo_1000@25-01-2016_20-35-35.jpg
photo_1000@25-01-2016_20-35.jpg

MyVideo-01.mp4
MyVideo.mp4

(SCL-Copy of MyVideo-01.mp4
(SCL-Copy of MyVideo.mp4

Removes everything from the last (-\d) sequence (1-3).

This is left unchanged, Copy of MyVideo-0123.mp4
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: It has been a while for me with regex...

Postby therube » Thu Aug 29, 2019 4:40 pm

MyVideo(tr)(MA).mp4


1:RegEx
Code: Select all
Match:  (.*)(\(tr\))(.*)
Replace:  \1 --- \3 --- \2

(dashes for readability, for me at least)

Match everything up to (tr)
Match (tr)
Match everything after (tr)

Rearrange things.

MyVideo(tr)(MA).mp4
MyVideo --- (MA) --- (tr).mp4
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: It has been a while for me with regex...

Postby JCN9801 » Sat Aug 31, 2019 8:12 am

Thanks a bunch!
Got the end digit striping to work.
My bad - typo.

Will try re-arrangement next day or two.

A work saving - thanks again!
---JCN :D
JCN9801
 
Posts: 5
Joined: Mon Aug 12, 2019 10:52 pm


Return to Regular Expressions


cron