Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7656999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:54:46+00:00 2026-05-31T12:54:46+00:00

I am trying to manage a Calibre library. Calibre uses Python regex to manipulate

  • 0

I am trying to manage a Calibre library. Calibre uses Python regex to manipulate database fields. In particular, you can specify the “pattern” and “repl” arguments to the sub() method. But that’s all you can do, no other coding. My current problem is that if there is no match for my group expression, Calibre reports an “unmatched group” error, and refuses to proceed.

Can I create a group that “always matches” but contains an empty string if it’s really not there?

I want to replace a field with a sub-string from the title, if the sub-string is found, or an empty string if it is not. I currently have mixed titles like:

Anne  McCaffrey - Pern 10 - The Renegades of Pern
Generation Warriors
The Mystery of Ireta: Dinosaur Planet & Dinosaur Planet Survivors
Anne McCaffrey - Tsw 7 - Ship That Returned

I want to pick out “Pern 10” from the first example, and “Tsw 7” from the fourth example, and write them to the series field. How can I do this?

My current, erroneous expression is

(((P<author>[^-]*?)- )?((?P<series>\w+)\W*(?P<series_index>\d*)\s-))?(?P<title>.*)

The only field I want at the moment is

\g<series>

Thanks for any ideas!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:54:47+00:00Added an answer on May 31, 2026 at 12:54 pm

    If I’m understanding the requirements correctly, it sounds like you should be able to write:

    ^(?:(?! - ).)*(?: - )?(?P<series>(?:(?! - ).)*)
    

    The initial ^(?:(?! - ).)* part will swallow everything before the first space-hyphen-space — or simply swallow everything, if there is no space-hyphen-space.

    The (?: - )? part will swallow the first space-hyphen-space if it’s there, or otherwise nothing.

    The (?:(?! - ).)* part inside the (?P<series>...) will swallow everything that hasn’t already been swallowed, up until the second space-hyphen-space (or end-of-string, if no second space-hyphen-space is found). If everything has already been swallowed, then this will simply be the empty string.

    In other words, the above is roughly equivalent to:

    @parts = split $title, / - /, 3;
    $series = ((@parts > 1) ? $parts[1] : '');
    

    Will that work for you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get Mylyn and Redmine work together so I can manage tasks
I am trying to manage my database connections and queries through OOP in PHP,
I'm trying to make an facebook application where i can manage my friends. Now
I'm trying to most efficiently manage a database table and get rid of old
I am trying to use the Net::SSH library to login and manage a host
I have a desktop application written in C#. It is trying to manage a
I'm trying to manually manage some geometry (spatial) columns in a rails model. When
I am trying to work out how to manage the following relationships A Store
I'm trying to figure out how to manage my event ids. Up to this
I'm trying to get Django's manage.py to run with modified settings files. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.