View Single Post
Old 08-22-2013, 03:51 AM   #24
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,737
Karma: 26785684
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Samsung Galaxy Tab S8 Ultra
\d match a digit

So \d\d will match a 2 digit sequence.

Or more general, \d+ will match any sequence of digits 1 or more long, just as .+ will match any sequence of characters, 1 long or longer.

Start of line can be matched using ^
End of line can be matched using $

You can match titles starting with digits like this:

^\d+.+$

And titles with digits in the middle like this:

^.+\d+.+$

By grouping the matches using parentheses you can do search and replace using the separate parts. Usually it is not necessary to use ^ and $, but sometimes it is. You have to test and see. And make sure you have a backup of your calibre library, and know how to restore it. There is NO UNDO if you make errors. But on the other hand there is a helpful test feature in calibre so you can test the regexp search and replace before you actually do it.

For instance:

Series 32 Title
(.+)(\d+)(.+)
Here group \1 will be "Series ", group \2 will be "32" and group \3 will be " Title".

Or

123 Title
(\d+)(.+)
\1="123", \2=" Title".

Title 456
(.+)(\d+)
\1="Title ", \2="456"

Most likely you would also like to match spaces, \s, outside the groups, like this:

Series 89 Title
(.+)\s(\d+)\s(.+)
\1="Series", \2="89", \3="Title" (Note that the spaces before and after the digits no longer are included in \1 and \3.)

To remove the digits from the beginning of a title yo can do this:

12 Title
Search title for ^(\d+)\s(.+) and replace title with \2.

Read more here: http://manual.calibre-ebook.com/regexp.html

Last edited by Adoby; 08-22-2013 at 10:12 AM. Reason: Replaced / with \
Adoby is offline   Reply With Quote