Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:31:34+00:00 2026-06-02T10:31:34+00:00

I’m sorry, but I haven’t been able to find a working solution from any

  • 0

I’m sorry, but I haven’t been able to find a working solution from any of the solutions Google’s been giving me (a couple of “recipes” on some site were pretty close, but way old and I haven’t found something that gives me the result I’m looking for.

I’m renaming files, so I have a function that spits out the filename, for this I’m just using ‘test_string’s:
So, all the dots, (and underscores) and stuff are removed first–since those are the most common thing all these professors do differently and makes all this stuff impossible to deal with (or look at) without removing.
5 Examples:

test_string_1 = 'legal.studies.131.race.relations.in.the.United.States.'

‘legal.studies’ –> ‘Legal Studies’

test_string_2 = 'mediastudies the triumph of bluray over hddvd' 

‘mediastudies’ –> ‘Media Studies’, ‘bluray’ –> ‘Blu-ray, ‘hddvd’ –> ‘HD DVD’

test_string_3 = 'computer Science Microsoft vs unix'

‘computer Science’ –> ‘Computer Science’, ‘unix’ –> ‘UNIX’

test_string_4 = 'Perception - metamers dts'

‘Perception’ would already be good (but who cares), big picture is they want to keep the audio information in there, so ‘dts’ –> DTS

test_string_5 = 'Perception - Cue Integration - flashing dot example aac20 xvid'

‘aac20’ –> ‘AAC2.0’, ‘xvid’ –> ‘XviD’

Currently I’m running this through something like:

new_string = re.sub(r'(?i)Legal(\s|-|)Studies', 'Legal Studies', re.sub(r'(?i)Sociology', 'Sociology', re.sub(r'(?i)Media(\s|-|)Studies', 'Media Studies', re.sub(r'(?i)UNIX', 'UNIX', re.sub(r'(?i)Blu(\s|-|)ray', 'Blu-ray', re.sub(r'(?i)HD(\s|-|)DVD', 'HD DVD', re.sub(r'(?i)xvid(\s|-|)', 'XviD', re.sub(r'(?i)aac(\s|-|)2(\s|-|\.|)0', 'AAC2.0', re.sub(r'(?i)dts', 'DTS', re.sub(r'\.', r' ', original_string.title()))))))))))

I have them all smushed together on one line; because I’m not changing/updating it much and (the way my brain/ADD works) it’s easier to have it as minimal/out-of-the-way as possible while I’m doing other things once I’m not messing with this part anymore.

So, with my example:

new_test_string_1 = 'Legal Studies 131 Race Relations In The United States'
new_test_string_2 = 'Media Studies The Triumph Of Blu-ray Over HD DVD'
new_test_string_3 = 'Computer Science Microsoft Vs UNIX'
new_test_string_4 = 'Perception - Metamers DTS'
new_test_string_5 = 'Perception - Cue Integration - Flashing Dot Example AAC2.0 XviD'

However, as I have more and more of these it’s really starting to become the kind of thing I want to have a dictionary or something for–I don’t want to blow up the code to anything crazy, but I’d like to be able to add new replacements as real life examples come up that need to be added (for example, there are a lot of audio codecs/containers/whatevers out there, and it looks like I might have to just throw them all in). I have no opinion about the method used by this master-list/dictionary/whatever.

Big picture: I’m fixing spaces and underscores in the filenames, replacing a bunch of shit with capitalization stuff (at the moment, universally title-casing it with the exception of the re.subs I’m making, which deal with plenty of cases where the capitalization isn’t perfect and there may or may not be a space, dash, or dot in the input that the output should have).

Similarly, a one-liner, unnamed (such as lambda) function would be preferable.

P.S.
Sorry for some of the weirdness and some of the initial lack of clarity. One of the problems here is in my major/studies most of the stuff is actually pretty straight-forward, it’s other classes that need all the Blu-ray, HD DVD, DTS, AAC2.0, XviD, etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:31:42+00:00Added an answer on June 2, 2026 at 10:31 am
    import re
    
    def string_fix(filename, dict):
        filename = filename.replace('.', ' ')
        for key, val in dict.items():
            filename = re.sub(key, val, filename, flags=re.IGNORECASE)
        return filename
    
    dict = {
             r'Legal[\s\-_]?Studies' : 'Legal Studies',
             r'Media[\s\-_]?Studies' : 'Media Studies',
             r'dts' : 'DTS',
             r'hd[\s\-_]?dvd': 'HD DVD',
             r'blu[\s\-_]?ray' : 'Blu-ray',
             r'unix' : 'UNIX',
             r'aac[\s\-_]?2[\.]?0' : 'AAC2.0',
             r'xvid' : 'XviD',
             r'computer[\s\-_]?science' : 'Computer Science'
         }
    
    string_1 = 'legal.studies.131.race.relations.in.the.United.States.'
    string_2 = 'mediastudies the triumph of bluray over hddvd'
    string_3 = 'computer Science Microsoft vs unix'
    string_4 = 'Perception - metamers dts'
    string_5 = 'Perception - Cue Integration - flashing dot example aac20 xvid'
    
    print(string_fix(string_1, dict))
    print(string_fix(string_2, dict))
    print(string_fix(string_3, dict))
    print(string_fix(string_4, dict))
    print(string_fix(string_5, dict))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.