Python Forum
Help creating a pattern using the re module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help creating a pattern using the re module
#4
(Jan-09-2019, 12:16 AM)micseydel Wrote: What's your code for the two-pass solution?

You mention that the 4th should not be renamed, but you actually remove a space. It might be good to clarify which it is.

Wow. I knew something was different. I couldn't find a way to edit my post, so allow me to correct it here.

I have written a python3 script to rename files based on a pattern input by the user. It has worked well, but I now am trying to create a pattern, and I am running into problems.

Correction:

I have four types of filenames:
filename1 - flubber.MP4
filename2.MP4
filename3 - flubber.mp4
filename4.mp4

I am trying to create a pattern that will work on all these file names and rename them all as:
filename1.mp4
filename2.mp4
filename3.mp4
filename4.mp4 (This one of course would not be renamed)

I can easily accomplish this in two passes, but I would like to accomplish it in one pass. Help?

(Jan-09-2019, 12:16 AM)Gribouillis Wrote: How do you easily accomplish this in two passes?

See my correction in response to micseydel.

My two-pass solution is:
1st pattern:
(.+)MP4$
Replacement:
\1mp4

2nd pattern:
(.+) - flubber(.+)
Replacement:
\1\2
Reply


Messages In This Thread
RE: Help creating a pattern using the re module - by zulu_likuum - Jan-09-2019, 06:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'no module named' when creating packages mbastida 4 4,119 Nov-30-2021, 10:43 AM
Last Post: Gribouillis
  ModuleNotFoundError: No module named 'psutil' after creating .exe ? ABhishek 3 11,632 Jul-30-2019, 01:44 PM
Last Post: ABhishek
  Regex, creating a pattern stahorse 5 3,294 Apr-24-2019, 08:29 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020