LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2004, 06:55 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
perl regex matching


because it is perl I will give it the benefit of the doubt and assume this is possible, rather than ask if it is possible I will ask how.

I am going to create a subroutine/function/meathod/whatever you want to call it to isolate the artist name in a directory of (Legal) mp3's

say it is like this:

directory:
Artist A - 22 - songa.mp3
Artist A - 22 - Songb.mp3
... the list goes on.
First off I have it strip character slike '-' and reduce all double spaces into single space, as well all characters are lowercased, also a text replacement replaces all '_' with space ' '
so what we have is:
artist a 22 songa
artist a 23 songb
artist a 24 songc
maybe one or 2 out of order or with the nunber missing
25 artist a songd
songe artist a
(By this point the .mp3 is also stripped)
I then need a way to isolate "artist a"
in other words I need it to run through all the string we now have and find a common string that at least 75% of the filenames checked have in common in this case all the files have "artist a" in there name, but nothing else would match across them. what would be the correct way to impliment such a search?

also it needs to do it on a word basis, as in "artist a songa" and "artist a songb" would only match the "artist a" not the "artist a song" because each time song is found it is followed by a character not a space, so the word as a whole is thrown away and not used in the match.

also it needs to differenciate between a number that is common and a number that is not:

say there is a band called "my number 3"
each song title would look liek this:
"my number 3 12 songname"
"my number 3 13 songnamea"
"my number 3 14 songnameb"
"my number 3 15 songnamec"

this should match "my number 3" becuase the 3 is also found in them all.

I am familiar with basic matching and some other regex, and I am very familiar with perl finishing off a class on it with 3 years+ total programming experiance, so you do not need to dumb it down to much or baby me through it.

Last edited by exodist; 11-14-2004 at 06:56 PM.
 
Old 11-15-2004, 01:42 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Why are you removing the delimiter? Just use:
$song="Artist A - 22 - songa.mp3";
$song=~s/\.mp3$//;
($artist,$num,$track)=split(/ - /g,$song);
print "Artist: $artist\nTrack: $track\n";
 
Old 11-15-2004, 10:50 PM   #3
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
not all the files in the directory will have the delimiter, I remove it to ensure consistancy in the procedure
and not make a special case for weather or nto there are delimeters.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regex Perl help igotlongestname Programming 2 09-14-2005 07:51 PM
regex matching things like å õ í ë ã è, etc. aunquarra Programming 2 05-04-2005 07:53 AM
simple perl and regex phlx Programming 6 12-03-2004 03:01 PM
perl: using 'substr' in regex ananthbv Programming 5 11-03-2004 01:58 AM
perl regex question JustinHoMi Programming 5 03-20-2002 07:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration