0

I am trying to use Calibre on my mac to organize my ebook library.

As a summer personal project, I created various epubs of my nephews' and nieces' school reports as keepsakes on my computer and phone. I had labeled the files as: Title_Last Name, First Name.epub

For example: Report on ATP Cycle_Doe, John.epub

With Calibre I found you can configure metadata from the file name: Link

For example:

(?P<title>.+) - (?P<author>[^_]+)

Would only work if the file name was: Title - First Name Last Name.epub

I tried:

(?P<title>.+)[^\w](?P<author>[^_]+)

And it would return the title as: Report on ATP Cycle Doe,
And the author as: John

Can anyone can help me figure out a RegEx expression to extract the title and author from the file name convention that I used?

Such that the title is: Report on ATP Cycle
And the author is: John Doe

It is much appreciated.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user3894951
  • 1
  • 1
  • 2
  • you mean this http://regex101.com/r/lP2hO0/6 ? Second group contains last name and the third group contains first name. – Avinash Raj Jul 31 '14 at 09:34
  • Hi, I used your expression but I believe Calibre requires the syntax for identifying the author's name: [Image](http://imgur.com/CPgSmLa) – user3894951 Jul 31 '14 at 12:30

1 Answers1

0

Use this:

^(?P<title>[^_]+)_(?P<author>.*)\.epub$

In the Regex Demo, look at the named groups in the right pane.

Explanation

  • The ^ anchor asserts that we are at the beginning of the string
  • (?P<title>[^_]+) captures chars that are not an underscore to the title capture group
  • (?P<author>.*) captures any chars to the author capture group
  • \.epub matches .epub
  • The $ anchor asserts that we are at the end of the string

Variation

If for some reason the regex is not supposed to match the .epub extension, use this instead:

^(?P<title>[^_]+)_(?P<author>[.^]+)
zx81
  • 41,100
  • 9
  • 89
  • 105
  • I used the above expression but Calibre did not read the syntax for the author: [First expression](http://imgur.com/SxXU2fE) [Second expression](http://imgur.com/7enpo2l) Can you offer another solution? I also appreciate your help and explanation in clarifying the syntax. Thank you. – user3894951 Jul 31 '14 at 12:37