09-23-2014, 10:48 PM | #1 |
enturbulated
Posts: 30
Karma: 130494
Join Date: May 2007
Device: Kobo Aura HD
|
regex for filename with muliple dots? (adding books)
SOLVED Trying to get a regex for filename with variable number of dots (<2).
I get the following from the tutorial and other threads, (thanks to Starson17 for all your generous contributions): Untick, "Read metadata from file contents rather than file name" and the regular expression Firstauthorname SurnameAuthor - Title.pdf works with (?P<author>[^_]+) - (?P<title>.+) while Firstauthorname SurnameAuthor. Title.pdf works with (?P<author>[^_]+)\. (?P<title>.+) However Firstauthorname SurnameAuthor. Title A. Title B. Title C. Title D. Volume 2..pdf doesn't work with anything I can find. I want everything between the first "dot white space" and ".pdf" to be read as the title. Real life example of file name: Dionysius of Halicarnassus. Roman Antiquities, IV. Books VI.49-VII.pdf How do I modify (?P<author>[^_]+)\. (?P<title>.+) so it ignores special characters after the first dot? Last edited by kite; 09-28-2014 at 09:13 AM. Reason: problem solved |
09-23-2014, 11:00 PM | #2 |
Wizard
Posts: 2,251
Karma: 3720310
Join Date: Jan 2009
Location: USA
Device: Kindle, iPad (not used much for reading)
|
You normally have to escape a period in a regex. Like this: \.. Otherwise it means any character.
|
Advert | |
|
09-24-2014, 04:38 AM | #3 |
enturbulated
Posts: 30
Karma: 130494
Join Date: May 2007
Device: Kobo Aura HD
|
Further experimenting reveals that it is not the "." dots that are the problem.
Filename: Agog Delm. Try This........WouldYou..FDasdf...pdf gives; Title: Try This........WouldYou..FDasdf.. Author: Agog Delm Just as I want. Edited: But any more dots next to spaces (after the first ". space" following the title) messes things up. Last edited by kite; 09-25-2014 at 12:29 AM. Reason: repair inaccurate description |
09-25-2014, 03:26 PM | #4 |
Enthusiast
Posts: 30
Karma: 752
Join Date: Nov 2010
Device: PB360
|
Does (?P<author>.+?)\. (?P<title>.+) work for you? It considers all characters before the first dot followed by a space as author and the rest as title.
Regexes are greedy by default which means that (?P<author>[^_]+)\. matches all characters (which are not '_') before the last dot followed by a space as author. See the note under Hey, neat! This is starting to make sense! in the tutorial on regexes. |
09-25-2014, 05:37 PM | #5 |
null operator (he/him)
Posts: 20,565
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I would fix the file names to match the pattern I have selected in the Add Books config.
File renamers are a dime a dozen, some have regex facilities, almost all feature a preview and many have an exclude. If I wanted to retain the existing filenames, I would create hardlinks, rename and add them to calibre and then trash 'em. BR |
Advert | |
|
09-28-2014, 09:09 AM | #6 | |
enturbulated
Posts: 30
Karma: 130494
Join Date: May 2007
Device: Kobo Aura HD
|
Quote:
Thanks for your help people. (?P<author>.+?)\. (?P<title>.+) does the trick nicely. And having read "Hey neat ... " for the fifth time has me thinking that I could have made the + in the first phrase of (?P<author>[^_]+)\. (?P<title>.+) non-greedy by adding a ? just so (?P<author>[^_]+?)\. (?P<title>.+) "Regexes are greedy by default which means that (?P<author>[^_]+)\. matches all characters (which are not '_') before the last dot followed by a space as author." I had tried many combinations and permutations but all in the second phrase of the expression as I ASSumed that the first phrase stopped matching at the first "\. " My grasp of regular expressions doesn't let me create and use them in Bulk File Rename yet. |
|
Tags |
adding books, regex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Adding books - regex help | tonyx3 | Library Management | 1 | 03-13-2013 08:21 AM |
Adding books with different filename structures | Sinnott | Library Management | 2 | 11-09-2012 08:12 AM |
Adding books with series in the filename | genright | Library Management | 5 | 06-13-2011 03:20 PM |
RegEx - filename metadata help | ejjenkins | Calibre | 4 | 12-28-2010 05:47 PM |
A little help adding books and using regex. | Dragonator | Calibre | 7 | 12-17-2010 06:57 PM |