View Single Post
Old 08-26-2009, 02:07 PM   #11
GinoAMelone
Junior Member
GinoAMelone began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Aug 2009
Device: Windows Mobile
Quote:
Originally Posted by TTC View Post
Hi, I've had a search through a few of these threads to see if anyone has asked this question before, but I couldn't find it, so apologies if I missed it somewhere.

A lot of my filenames are in the following format:
Surname, Firstname - Title
or
Surname, Firstname - Series # - Title

My problem is that when I start the expression with the default (?P<author>[^_]+) it puts the author details in back to front and messes up the author sort as well.

How do I go about reversing the surname and the first name in the expression so that the Author field is populated correctly? I've looked at the guide for regular expressions, but it's a bit above my head at the moment, although I'm persevering to try and wrap my head around it.
What he said!!!

Here's my latest RegExp:
Code:
^((?P<author>([^\-_0-9]+)(?=\s*-\s*)(?!\s*-\s*[0-9.]+)|\b))(\s*-\s*)?((?P<series>[^0-9\-]+)(\s*-\s*)?(?P<series_index>[0-9.]+)\s*-\s*)?(?P<title>[^\-_0-9]+)
It can currently match any of these formats:
  • Series Name 1 - Book Title.txt
  • Author - Series Name 1 - Book Title.txt
  • Author - Series Name - 1 - Book Title.txt
  • Author - Book Title.txt
  • Series Name - 1 - Book Title.txt
The only things it can't handle right now are:
  1. The format of author's name mentioned by TTC
  2. Different ordering of the fields in the file name

I tried using something like this to define multiple orderings. But, I can't reuse a group name. But then, with all the different formats the above RegExp can handle now, it would probably match anything with a reversed order anyway.
Code:
((?<author>...) - (?<title>...))|((?<title>...) - (?<author>...))
GinoAMelone is offline