Regular Expression assistance


#1

Ok, need a little help here....

First off, anyone know of a good Regular Expression tutorial ? I'd like to learn how to do this myself...

While I dig around for one, would appreciate it if someone could enlighten me as to how I do the followig :

  • search for x-x and replace with x - x where x is any character
  • change the string track - artist - title (pres artist2) (mix_name) to track - artist pres artist2 - title (mix_name)
Fun facts about the second one :
  • 'track' and '(mix_name)' are optional
  • 'pres' may be 'feat' or 'vs.' - but all files will have one of the three
I would greatly appreciate any assistance offered.

#2

1:
(.)-(.)
$1 - $2

2:
^(\d{1,2}\s-\s)?(.)\s-\s(.)\s((.))(\s(.))?
$1$2 $4 - $3$5

Mp3tag helpfile is good


#3

Thanks for the help d4n0, but the second one didn't quite work.

Your suggestion resulted in :
track - artist mix_name - title (pres artist2)

when I am looking for :
track - artist pres artist2 - title (mix_name)

When I broke the results down into $1 - $2 - $3 - $4 - $5, it does not appear to be seperating the string title (pres artist2) into two compenents.

I checked the help file as you suggested, but apparently I am daft...

Any more suggestions ?


#4

i have no clue why title (pres artist2) is always together :frowning:


#5

Check the greedyness of the repeats in the parenthesis part. The regular expression
^(\d{1,2}\s-\s)?(.)\s-\s(.)\s((.?))(\s(.?))
should work.

Best regards,
~ Florian


#6

it does not work when there is no (mix_name) at the end


#7

Oh yes, you're right! I've changed all repeats to be non-greedy in your regular expression and now it should work for both cases.

^(\d{1,2}\s-\s)?(.?)\s-\s(.?)\s((.?))(\s(.))?
$1$2 $4 - $3$5

Best regards,
~ Florian


#8

awesome, yes seems to be fine now
and i gotta find out what greedyness exactly is :smiley:


#9

You can translate greedyness with "Gierigkeit". Greedy (standard) repeats are eating as much characters as possible - the non-greedy ones (those with the question mark after the repeat character) don't :slight_smile:

~ Florian


#10

you guys rock....