"Fossies" - the Fresh Open Source Software Archive
Member "calibre-3.45.2/translations/manual/regexp.pot" (12 Jul 2019, 23482 Bytes) of package /linux/misc/calibre-3.45.2.tar.xz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard
) with prefixed line numbers.
Alternatively you can here view
the uninterpreted source code file.
1 # SOME DESCRIPTIVE TITLE.
2 # Copyright (C) Kovid Goyal
3 # This file is distributed under the same license as the calibre package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: calibre 3.45.2\n"
10 "Report-Msgid-Bugs-To: \n"
11 "POT-Creation-Date: 2019-07-12 20:47+0530\n"
12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 "Language-Team: LANGUAGE <LL@li.org>\n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
19 #: ../../home/kovid/work/calibre/manual/regexp.rst:4
20 msgid "All about using regular expressions in calibre"
21 msgstr ""
23 #: ../../home/kovid/work/calibre/manual/regexp.rst:6
24 msgid "Regular expressions are features used in many places in calibre to perform sophisticated manipulation of e-book content and metadata. This tutorial is a gentle introduction to getting you started with using regular expressions in calibre."
25 msgstr ""
27 #: ../../home/kovid/work/calibre/manual/regexp.rst:11
28 msgid "Contents"
29 msgstr ""
31 #: ../../home/kovid/work/calibre/manual/regexp.rst:14
32 msgid "First, a word of warning and a word of courage"
33 msgstr ""
35 #: ../../home/kovid/work/calibre/manual/regexp.rst:16
36 msgid "This is, inevitably, going to be somewhat technical- after all, regular expressions are a technical tool for doing technical stuff. I'm going to have to use some jargon and concepts that may seem complicated or convoluted. I'm going to try to explain those concepts as clearly as I can, but really can't do without using them at all. That being said, don't be discouraged by any jargon, as I've tried to explain everything new. And while regular expressions themselves may seem like an arcane, black magic (or, to be more prosaic, a random string of mumbo-jumbo letters and signs), I promise that they are not all that complicated. Even those who understand regular expressions really well have trouble reading the more complex ones, but writing them isn't as difficult- you construct the expression step by step. So, take a step and follow me into the rabbit hole."
37 msgstr ""
39 #: ../../home/kovid/work/calibre/manual/regexp.rst:19
40 msgid "Where in calibre can you use regular expressions?"
41 msgstr ""
43 #: ../../home/kovid/work/calibre/manual/regexp.rst:21
44 msgid "There are a few places calibre uses regular expressions. There's the :guilabel:`Search & replace` in conversion options, metadata detection from filenames in the import settings and Search & replace when editing the metadata of books in bulk. The calibre book editor can also use regular expressions in its search and replace feature."
45 msgstr ""
47 #: ../../home/kovid/work/calibre/manual/regexp.rst:28
48 msgid "What on earth *is* a regular expression?"
49 msgstr ""
51 #: ../../home/kovid/work/calibre/manual/regexp.rst:30
52 msgid "A regular expression is a way to describe sets of strings. A single regular expression can *match* a number of different strings. This is what makes regular expression so powerful -- they are a concise way of describing a potentially large number of variations."
53 msgstr ""
55 #: ../../home/kovid/work/calibre/manual/regexp.rst:32
56 msgid "I'm using string here in the sense it is used in programming languages: a string of one or more characters, characters including actual characters, numbers, punctuation and so-called whitespace (linebreaks, tabulators etc.). Please note that generally, uppercase and lowercase characters are not considered the same, thus \"a\" being a different character from \"A\" and so forth. In calibre, regular expressions are case insensitive in the Search bar, but not in the conversion options. There's a way to make every regular expression case insensitive, but we'll discuss that later. It gets complicated because regular expressions allow for variations in the strings it matches, so one expression can match multiple strings, which is why people bother using them at all. More on that in a bit."
57 msgstr ""
59 #: ../../home/kovid/work/calibre/manual/regexp.rst:35
60 msgid "Care to explain?"
61 msgstr ""
63 #: ../../home/kovid/work/calibre/manual/regexp.rst:37
64 msgid "Well, that's why we're here. First, this is the most important concept in regular expressions: *A string by itself is a regular expression that matches itself*. That is to say, if I wanted to match the string ``\"Hello, World!\"`` using a regular expression, the regular expression to use would be ``Hello, World!``. And yes, it really is that simple. You'll notice, though, that this *only* matches the exact string ``\"Hello, World!\"``, not e.g. ``\"Hello, wOrld!\"`` or ``\"hello, world!\"`` or any other such variation."
65 msgstr ""
67 #: ../../home/kovid/work/calibre/manual/regexp.rst:40
68 msgid "That doesn't sound too bad. What's next?"
69 msgstr ""
71 #: ../../home/kovid/work/calibre/manual/regexp.rst:42
72 msgid "Next is the beginning of the really good stuff. Remember where I said that regular expressions can match multiple strings? This is where it gets a little more complicated. Say, as a somewhat more practical exercise, the e-book you wanted to convert had a nasty footer counting the pages, like \"Page 5 of 423\". Obviously the page number would rise from 1 to 423, thus you'd have to match 423 different strings, right? Wrong, actually: regular expressions allow you to define sets of characters that are matched: To define a set, you put all the characters you want to be in the set into square brackets. So, for example, the set ``[abc]`` would match either the character \"a\", \"b\" or \"c\". *Sets will always only match one of the characters in the set*. They \"understand\" character ranges, that is, if you wanted to match all the lower case characters, you'd use the set ``[a-z]`` for lower- and uppercase characters you'd use ``[a-zA-Z]`` and so on. Got the idea? So, obviously, using the expression ``Page [0-9] of 423`` you'd be able to match the first 9 pages, thus reducing the expressions needed to three: The second expression ``Page [0-9][0-9] of 423`` would match all two-digit page numbers, and I'm sure you can guess what the third expression would look like. Yes, go ahead. Write it down."
73 msgstr ""
75 #: ../../home/kovid/work/calibre/manual/regexp.rst:45
76 msgid "Hey, neat! This is starting to make sense!"
77 msgstr ""
79 #: ../../home/kovid/work/calibre/manual/regexp.rst:47
80 msgid "I was hoping you'd say that. But brace yourself, now it gets even better! We just saw that using sets, we could match one of several characters at once. But you can even repeat a character or set, reducing the number of expressions needed to handle the above page number example to one. Yes, ONE! Excited? You should be! It works like this: Some so-called special characters, \"+\", \"?\" and \"*\", *repeat the single element preceding them*. (Element means either a single character, a character set, an escape sequence or a group (we'll learn about those last two later)- in short, any single entity in a regular expression.) These characters are called wildcards or quantifiers. To be more precise, \"?\" matches *0 or 1* of the preceding element, \"*\" matches *0 or more* of the preceding element and \"+\" matches *1 or more* of the preceding element. A few examples: The expression ``a?`` would match either \"\" (which is the empty string, not strictly useful in this case) or \"a\", the expression ``a*`` would match \"\", \"a\", \"aa\" or any number of a's in a row, and, finally, the expression ``a+`` would match \"a\", \"aa\" or any number of a's in a row (Note: it wouldn't match the empty string!). Same deal for sets: The expression ``[0-9]+`` would match *every integer number there is*! I know what you're thinking, and you're right: If you use that in the above case of matching page numbers, wouldn't that be the single one expression to match all the page numbers? Yes, the expression ``Page [0-9]+ of 423`` would match every page number in that book!"
81 msgstr ""
83 #: ../../home/kovid/work/calibre/manual/regexp.rst:50
84 msgid "A note on these quantifiers: They generally try to match as much text as possible, so be careful when using them. This is called \"greedy behaviour\"- I'm sure you get why. It gets problematic when you, say, try to match a tag. Consider, for example, the string ``\"<p class=\"calibre2\">Title here</p>\"`` and let's say you'd want to match the opening tag (the part between the first pair of angle brackets, a little more on tags later). You'd think that the expression ``<p.*>`` would match that tag, but actually, it matches the whole string! (The character \".\" is another special character. It matches anything *except* linebreaks, so, basically, the expression ``.*`` would match any single line you can think of.) Instead, try using ``<p.*?>`` which makes the quantifier ``\"*\"`` non-greedy. That expression would only match the first opening tag, as intended. There's actually another way to accomplish this: The expression ``<p[^>]*>`` will match that same opening tag- you'll see why after the next section. Just note that there quite frequently is more than one way to write a regular expression."
85 msgstr ""
87 #: ../../home/kovid/work/calibre/manual/regexp.rst:54
88 msgid "Well, these special characters are very neat and all, but what if I wanted to match a dot or a question mark?"
89 msgstr ""
91 #: ../../home/kovid/work/calibre/manual/regexp.rst:56
92 msgid "You can of course do that: Just put a backslash in front of any special character and it is interpreted as the literal character, without any special meaning. This pair of a backslash followed by a single character is called an escape sequence, and the act of putting a backslash in front of a special character is called escaping that character. An escape sequence is interpreted as a single element. There are of course escape sequences that do more than just escaping special characters, for example ``\"\\t\"`` means a tabulator. We'll get to some of the escape sequences later. Oh, and by the way, concerning those special characters: Consider any character we discuss in this introduction as having some function to be special and thus needing to be escaped if you want the literal character."
93 msgstr ""
95 #: ../../home/kovid/work/calibre/manual/regexp.rst:59
96 msgid "So, what are the most useful sets?"
97 msgstr ""
99 #: ../../home/kovid/work/calibre/manual/regexp.rst:61
100 msgid "Knew you'd ask. Some useful sets are ``[0-9]`` matching a single number, ``[a-z]`` matching a single lowercase letter, ``[A-Z]`` matching a single uppercase letter, ``[a-zA-Z]`` matching a single letter and ``[a-zA-Z0-9]`` matching a single letter or number. You can also use an escape sequence as shorthand::"
101 msgstr ""
103 #: ../../home/kovid/work/calibre/manual/regexp.rst:68
104 msgid "\"Whitespace\" is a term for anything that won't be printed. These characters include space, tabulator, line feed, form feed and carriage return."
105 msgstr ""
107 #: ../../home/kovid/work/calibre/manual/regexp.rst:70
108 msgid "As a last note on sets, you can also define a set as any character *but* those in the set. You do that by including the character ``\"^\"`` as the *very first character in the set*. Thus, ``[^a]`` would match any character excluding \"a\". That's called complementing the set. Those escape sequence shorthands we saw earlier can also be complemented: ``\"\\D\"`` means any non-number character, thus being equivalent to ``[^0-9]``. The other shorthands can be complemented by, you guessed it, using the respective uppercase letter instead of the lowercase one. So, going back to the example ``<p[^>]*>`` from the previous section, now you can see that the character set it's using tries to match any character except for a closing angle bracket."
109 msgstr ""
111 #: ../../home/kovid/work/calibre/manual/regexp.rst:73
112 msgid "But if I had a few varying strings I wanted to match, things get complicated?"
113 msgstr ""
115 #: ../../home/kovid/work/calibre/manual/regexp.rst:75
116 msgid "Fear not, life still is good and easy. Consider this example: The book you're converting has \"Title\" written on every odd page and \"Author\" written on every even page. Looks great in print, right? But in e-books, it's annoying. You can group whole expressions in normal parentheses, and the character ``\"|\"`` will let you match *either* the expression to its right *or* the one to its left. Combine those and you're done. Too fast for you? Okay, first off, we group the expressions for odd and even pages, thus getting ``(Title)(Author)`` as our two needed expressions. Now we make things simpler by using the vertical bar (``\"|\"`` is called the vertical bar character): If you use the expression ``(Title|Author)`` you'll either get a match for \"Title\" (on the odd pages) or you'd match \"Author\" (on the even pages). Well, wasn't that easy?"
117 msgstr ""
119 #: ../../home/kovid/work/calibre/manual/regexp.rst:77
120 msgid "You can, of course, use the vertical bar without using grouping parentheses, as well. Remember when I said that quantifiers repeat the element preceding them? Well, the vertical bar works a little differently: The expression \"Title|Author\" will also match either the string \"Title\" or the string \"Author\", just as the above example using grouping. *The vertical bar selects between the entire expression preceding and following it*. So, if you wanted to match the strings \"Calibre\" and \"calibre\" and wanted to select only between the upper- and lowercase \"c\", you'd have to use the expression ``(c|C)alibre``, where the grouping ensures that only the \"c\" will be selected. If you were to use ``c|Calibre``, you'd get a match on the string \"c\" or on the string \"Calibre\", which isn't what we wanted. In short: If in doubt, use grouping together with the vertical bar."
121 msgstr ""
123 #: ../../home/kovid/work/calibre/manual/regexp.rst:80
124 msgid "You missed..."
125 msgstr ""
127 #: ../../home/kovid/work/calibre/manual/regexp.rst:82
128 msgid "... wait just a minute, there's one last, really neat thing you can do with groups. If you have a group that you previously matched, you can use references to that group later in the expression: Groups are numbered starting with 1, and you reference them by escaping the number of the group you want to reference, thus, the fifth group would be referenced as ``\\5``. So, if you searched for ``([^ ]+) \\1`` in the string \"Test Test\", you'd match the whole string!"
129 msgstr ""
131 #: ../../home/kovid/work/calibre/manual/regexp.rst:86
132 msgid "In the beginning, you said there was a way to make a regular expression case insensitive?"
133 msgstr ""
135 #: ../../home/kovid/work/calibre/manual/regexp.rst:88
136 msgid "Yes, I did, thanks for paying attention and reminding me. You can tell calibre how you want certain things handled by using something called flags. You include flags in your expression by using the special construct ``(?flags go here)`` where, obviously, you'd replace \"flags go here\" with the specific flags you want. For ignoring case, the flag is ``i``, thus you include ``(?i)`` in your expression. Thus, ``(?i)test`` would match \"Test\", \"tEst\", \"TEst\" and any case variation you could think of."
137 msgstr ""
139 #: ../../home/kovid/work/calibre/manual/regexp.rst:90
140 msgid "Another useful flag lets the dot match any character at all, *including* the newline, the flag ``s``. If you want to use multiple flags in an expression, just put them in the same statement: ``(?is)`` would ignore case and make the dot match all. It doesn't matter which flag you state first, ``(?si)`` would be equivalent to the above."
141 msgstr ""
143 #: ../../home/kovid/work/calibre/manual/regexp.rst:93
144 msgid "I think I'm beginning to understand these regular expressions now... how do I use them in calibre?"
145 msgstr ""
147 #: ../../home/kovid/work/calibre/manual/regexp.rst:96
148 msgid "Conversions"
149 msgstr ""
151 #: ../../home/kovid/work/calibre/manual/regexp.rst:98
152 msgid "Let's begin with the conversion settings, which is really neat. In the :guilabel:`Search & replace` part, you can input a regexp (short for regular expression) that describes the string that will be replaced during the conversion. The neat part is the wizard. Click on the wizard staff and you get a preview of what calibre \"sees\" during the conversion process. Scroll down to the string you want to remove, select and copy it, paste it into the regexp field on top of the window. If there are variable parts, like page numbers or so, use sets and quantifiers to cover those, and while you're at it, remember to escape special characters, if there are some. Hit the button labeled :guilabel:`Test` and calibre highlights the parts it would replace were you to use the regexp. Once you're satisfied, hit OK and convert. Be careful if your conversion source has tags like this example::"
153 msgstr ""
155 #: ../../home/kovid/work/calibre/manual/regexp.rst:108
156 msgid "(shamelessly ripped out of `this thread <https://www.mobileread.com/forums/showthread.php?t=75594\">`_). You'd have to remove some of the tags as well. In this example, I'd recommend beginning with the tag ``<b class=\"calibre2\">``, now you have to end with the corresponding closing tag (opening tags are ``<tag>``, closing tags are ``</tag>``), which is simply the next ``</b>`` in this case. (Refer to a good HTML manual or ask in the forum if you are unclear on this point.) The opening tag can be described using ``<b.*?>``, the closing tag using ``</b>``, thus we could remove everything between those tags using ``<b.*?>.*?</b>``. But using this expression would be a bad idea, because it removes everything enclosed by <b>- tags (which, by the way, render the enclosed text in bold print), and it's a fair bet that we'll remove portions of the book in this way. Instead, include the beginning of the enclosed string as well, making the regular expression ``<b.*?>\\s*Generated\\s+by\\s+ABC\\s+Amber\\s+LIT.*?</b>`` The ``\\s`` with quantifiers are included here instead of explicitly using the spaces as seen in the string to catch any variations of the string that might occur. Remember to check what calibre will remove to make sure you don't remove any portions you want to keep if you test a new expression. If you only check one occurrence, you might miss a mismatch somewhere else in the text. Also note that should you accidentally remove more or fewer tags than you actually wanted to, calibre tries to repair the damaged code after doing the removal."
157 msgstr ""
159 #: ../../home/kovid/work/calibre/manual/regexp.rst:111
160 msgid "Adding books"
161 msgstr ""
163 #: ../../home/kovid/work/calibre/manual/regexp.rst:113
164 msgid "Another thing you can use regular expressions for is to extract metadata from filenames. You can find this feature in the \"Adding books\" part of the settings. There's a special feature here: You can use field names for metadata fields, for example ``(?P<title>)`` would indicate that calibre uses this part of the string as book title. The allowed field names are listed in the windows, together with another nice test field. An example: Say you want to import a whole bunch of files named like ``Classical Texts: The Divine Comedy by Dante Alighieri.mobi``. (Obviously, this is already in your library, since we all love classical italian poetry) or ``Science Fiction epics: The Foundation Trilogy by Isaac Asimov.epub``. This is obviously a naming scheme that calibre won't extract any meaningful data out of - its standard expression for extracting metadata is ``(?P<title>.+) - (?P<author>[^_]+)``. A regular expression that works here would be ``[a-zA-Z]+: (?P<title>.+) by (?P<author>.+)``. Please note that, inside the group for the metadata field, you need to use expressions to describe what the field actually matches. And also note that, when using the test field calibre provides, you need to add the file extension to your testing filename, otherwise you won't get any matches at all, despite using a working expression."
165 msgstr ""
167 #: ../../home/kovid/work/calibre/manual/regexp.rst:117
168 msgid "Bulk editing metadata"
169 msgstr ""
171 #: ../../home/kovid/work/calibre/manual/regexp.rst:119
172 msgid "The last part is regular expression search and replace in metadata fields. You can access this by selecting multiple books in the library and using bulk metadata edit. Be very careful when using this last feature, as it can do **Very Bad Things** to your library! Doublecheck that your expressions do what you want them to using the test fields, and only mark the books you really want to change! In the regular expression search mode, you can search in one field, replace the text with something and even write the result into another field. A practical example: Say your library contained the books of Frank Herbert's Dune series, named after the fashion ``Dune 1 - Dune``, ``Dune 2 - Dune Messiah`` and so on. Now you want to get ``Dune`` into the series field. You can do that by searching for ``(.*?) \\d+ - .*`` in the title field and replacing it with ``\\1`` in the series field. See what I did there? That's a reference to the first group you're replacing the series field with. Now that you have the series all set, you only need to do another search for ``.*? -`` in the title field and replace it with ``\"\"`` (an empty string), again in the title field, and your metadata is all neat and tidy. Isn't that great? By the way, instead of replacing the entire field, you can also append or prepend to the field, so, if you *wanted* the book title to be prepended with series info, you could do that as well. As you by now have undoubtedly noticed, there's a checkbox labeled :guilabel:`Case sensitive`, so you won't have to use flags to select behaviour here."
173 msgstr ""
175 #: ../../home/kovid/work/calibre/manual/regexp.rst:121
176 msgid "Well, that just about concludes the very short introduction to regular expressions. Hopefully I'll have shown you enough to at least get you started and to enable you to continue learning by yourself- a good starting point would be the `Python documentation for regexps <https://docs.python.org/2/library/re.html>`_."
177 msgstr ""
179 #: ../../home/kovid/work/calibre/manual/regexp.rst:123
180 msgid "One last word of warning, though: Regexps are powerful, but also really easy to get wrong. calibre provides really great testing possibilities to see if your expressions behave as you expect them to. Use them. Try not to shoot yourself in the foot. (God, I love that expression...) But should you, despite the warning, injure your foot (or any other body parts), try to learn from it."
181 msgstr ""
183 #: ../../home/kovid/work/calibre/manual/regexp.rst:127
184 msgid "Quick reference"
185 msgstr ""
187 #: ../../home/kovid/work/calibre/manual/regexp.rst:135
188 msgid "Credits"
189 msgstr ""
191 #: ../../home/kovid/work/calibre/manual/regexp.rst:137
192 msgid "Thanks for helping with tips, corrections and such:"
193 msgstr ""
195 #: ../../home/kovid/work/calibre/manual/regexp.rst:139
196 msgid "ldolse"
197 msgstr ""
199 #: ../../home/kovid/work/calibre/manual/regexp.rst:140
200 msgid "kovidgoyal"
201 msgstr ""
203 #: ../../home/kovid/work/calibre/manual/regexp.rst:141
204 msgid "chaley"
205 msgstr ""
207 #: ../../home/kovid/work/calibre/manual/regexp.rst:142
208 msgid "dwanthny"
209 msgstr ""
211 #: ../../home/kovid/work/calibre/manual/regexp.rst:143
212 msgid "kacir"
213 msgstr ""
215 #: ../../home/kovid/work/calibre/manual/regexp.rst:144
216 msgid "Starson17"
217 msgstr ""
219 #: ../../home/kovid/work/calibre/manual/regexp.rst:145
220 msgid "Orpheu"
221 msgstr ""
223 #: ../../home/kovid/work/calibre/manual/regexp.rst:147
224 msgid "For more about regexps see `The Python User Manual <https://docs.python.org/2/library/re.html>`_."
225 msgstr ""