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

  • SEARCH
  • Home
  • 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 7490777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:46:01+00:00 2026-05-29T15:46:01+00:00

I have a question about regex/Python. Sorry if this topic has been discussed millions

  • 0

I have a question about regex/Python. Sorry if this topic has been discussed millions of times – usually I find the answers on so/google etc. but I’m stuck in the millions of answers with this one.. (To be honest – I own a regex book, but somehow I’m too stupid to really understand it…)

For a music-management-system I need to extract information out of paths, providing different sets of options. Here two examples:

If the path is: (Case 1)

"/The Prodigy/The Fat Of The Land/04 - Funky Stuff.flac"

it should extract:

  • artist: “The Prodigy”
  • release: “The Fat Of The Land”
  • Tracknumber: 4
  • Title: “Funky Stuff”

And for eg: (Case 2)

"/[XLR 483] The Fat Of The Land/04 - The Prodigy - The  Funky Stuff.flac"

should extract:

  • catno: “XLR 483”
  • release: “The Fat Of The Land”
  • Tracknumber: 4
  • artist: “The Prodigy”
  • Title: “Funky Stuff”

There is no need for a regex that covers both cases, these are just two examples. I’ll then provide them as options (or starting-point to add own ones).

Any help would be greatly appreciated!

@ S.Lott: I don’t have a regex for this, I started with splitting the string:

parts = rel_path.split('/')       
track = parts[-1]
release = parts[-2]
artist = parts[-3]

but this looks like an extremely inflexible and un-elegant solution to me.

edit:

So far I have something like:

pattern = re.compile('^/(?P<artist>[a-zA-Z0-9 ]+)/(?P<release>[a-zA-Z0-9 ]+)/(?P<track>[a-zA-Z0-9 -_]+).[a-zA-Z]*.*')


rel_path = '/The Prodigy/The Fat Of The Land/04 - Funky Stuff.flac'

match = pattern.search(rel_path)

artist = match.group('artist')
release = match.group('release')
track = match.group('track')
  • 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-05-29T15:46:02+00:00Added an answer on May 29, 2026 at 3:46 pm

    Although not necessary, but re is handy choice for this problem.

    import re
    pattern = re.compile(r"/(?P<artist>[a-zA-Z0-9 ]+?)/(?P<release>[a-zA-Z0-9 ]+?)/(?P<tracknumber>\d+?) - (?P<title>[a-zA-Z0-9 ]+?).flac")
    s = "/The Prodigy/The Fat Of The Land/04 - Funky Stuff.flac"
    m = pattern.search(s)
    print m.group('artist')
    print m.group('release')
    print m.group('track number')
    print m.group('title')
    

    I use expressions such as [a-zA-Z0-9 ] to explicitly specify the chars I expect in the string. It is just my preference to have a white-list-like regex to make the code more secure. There are many other ways to compose equivalent patterns. You will find all you need here http://docs.python.org/library/re.html, you don’t need a book for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about a regex. Given this part of a regex: (.[^\\.]+)
I Have a question about finding html tags using Java and Regex. I am
I have a question about locking. This doesn't have to be only about record
I have a question about using os.execvp in Python. I have the following bit
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about this question . I posted a reply there but
I know very little about regex so this has proven very challenging for me.
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have a question about using streams in .NET to load files from disk.

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.