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.

2
  • you mean this regex101.com/r/lP2hO0/6 ? Second group contains last name and the third group contains first name. Jul 31, 2014 at 9:34
  • Hi, I used your expression but I believe Calibre requires the <author> syntax for identifying the author's name: Image Jul 31, 2014 at 12:30

1 Answer 1

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>[.^]+)
1
  • I used the above expression but Calibre did not read the syntax for the author: First expression Second expression Can you offer another solution? I also appreciate your help and explanation in clarifying the syntax. Thank you. Jul 31, 2014 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.