Debian Codegraph @

translations/manual/zh_CN/regexp.po

raw
1 # SOME DESCRIPTIVE TITLE.
2 # Copyright (C) Kovid Goyal
3 # This file is distributed under the same license as the calibre package.
4 #
5 # Translators:
6 # RERBIN MA, 2026
7 # tony shen <[email protected]>, 2024
8 msgid ""
9 msgstr ""
10 "Project-Id-Version: calibre\n"
11 "Report-Msgid-Bugs-To: \n"
12 "POT-Creation-Date: 2026-03-12 02:31+0000\n"
13 "PO-Revision-Date: 2014-06-17 08:35+0000\n"
14 "Last-Translator: RERBIN MA, 2026\n"
15 "Language-Team: Chinese (China) (http://app.transifex.com/calibre/calibre/language/zh_CN/)\n"
16 "MIME-Version: 1.0\n"
17 "Content-Type: text/plain; charset=UTF-8\n"
18 "Content-Transfer-Encoding: 8bit\n"
19 "Language: zh_CN\n"
20 "Plural-Forms: nplurals=1; plural=0;\n"
21
22 #: ../../../__w/calibre/calibre/manual/regexp.rst:4
23 msgid "All about using regular expressions in calibre"
24 msgstr "关于在 calibre 中使用正则表达式的所有内容"
25
26 #: ../../../__w/calibre/calibre/manual/regexp.rst:6
27 msgid ""
28 "Regular expressions are features used in many places in calibre to perform "
29 "sophisticated manipulation of e-book content and metadata. This tutorial is "
30 "a gentle introduction to getting you started with using regular expressions "
31 "in calibre."
32 msgstr "正则表达式是 calibre 中许多地方使用的功能,用于对电子书内容和元数据执行复杂的操作。 本教程简要介绍了如何开始在 calibre 中使用正则表达式。"
33
34 #: ../../../__w/calibre/calibre/manual/regexp.rst:11
35 msgid "Contents"
36 msgstr "目录"
37
38 #: ../../../__w/calibre/calibre/manual/regexp.rst:14
39 msgid "First, a word of warning and a word of courage"
40 msgstr "首先,一句警告和一句勇气"
41
42 #: ../../../__w/calibre/calibre/manual/regexp.rst:16
43 msgid ""
44 "This is, inevitably, going to be somewhat technical- after all, regular "
45 "expressions are a technical tool for doing technical stuff. I'm going to "
46 "have to use some jargon and concepts that may seem complicated or "
47 "convoluted. I'm going to try to explain those concepts as clearly as I can, "
48 "but really can't do without using them at all. That being said, don't be "
49 "discouraged by any jargon, as I've tried to explain everything new. And "
50 "while regular expressions themselves may seem like an arcane, black magic "
51 "(or, to be more prosaic, a random string of mumbo-jumbo letters and signs), "
52 "I promise that they are not all that complicated. Even those who understand "
53 "regular expressions really well have trouble reading the more complex ones, "
54 "but writing them isn't as difficult- you construct the expression step by "
55 "step. So, take a step and follow me into the rabbit hole."
56 msgstr "这不可避免地会有些技术性——毕竟,正则表达式是一种用于完成技术工作的技术工具。 我将不得不使用一些看起来复杂或令人费解的术语和概念。 我将尝试尽可能清楚地解释这些概念,但实际上根本无法不使用它们。 话虽如此,不要因为任何行话而气馁,因为我已经尝试解释所有新内容。虽然正则表达式本身可能看起来像是一种神秘的黑魔法(或者,更平淡地说,是一串随机的繁琐字母和符号),但我保证它们并不那么复杂。 即使那些非常了解正则表达式的人在阅读更复杂的表达式时也会遇到困难,但是编写它们并不那么困难 - 您可以逐步构建表达式。 那么,迈出一步,跟我一起进入兔子洞吧。"
57
58 #: ../../../__w/calibre/calibre/manual/regexp.rst:19
59 msgid "Where in calibre can you use regular expressions?"
60 msgstr "calibre 中哪里可以使用正则表达式?"
61
62 #: ../../../__w/calibre/calibre/manual/regexp.rst:21
63 msgid ""
64 "There are a few places calibre uses regular expressions. There's the "
65 ":guilabel:`Search & replace` in conversion options, metadata detection from "
66 "filenames in the import settings and Search & replace when editing the "
67 "metadata of books in bulk. The calibre book editor can also use regular "
68 "expressions in its :guilabel:`Search and replace` feature. Finally, you can "
69 "use regular expressions when searching the calibre book list and when "
70 "searching inside the calibre E-book viewer."
71 msgstr "calibre 有几个地方使用了正则表达式。 转换选项中有搜索和替换,导入设置中的文件名元数据检测以及批量编辑图书元数据时的搜索和替换。 calibre 图书编辑器还可以在其搜索和替换功能中使用正则表达式。 最后,您可以在搜索 calibre 图书列表以及在 calibre 电子书阅读器内搜索时使用正则表达式。"
72
73 #: ../../../__w/calibre/calibre/manual/regexp.rst:30
74 msgid "What on earth *is* a regular expression?"
75 msgstr "正则表达式到底是什么?"
76
77 #: ../../../__w/calibre/calibre/manual/regexp.rst:32
78 msgid ""
79 "A regular expression is a way to describe sets of strings. A single regular "
80 "expression can *match* a number of different strings. This is what makes "
81 "regular expression so powerful -- they are a concise way of describing a "
82 "potentially large number of variations."
83 msgstr "正则表达式是一种描述字符串集的方法。 单个正则表达式可以“匹配”多个不同的字符串。 这就是正则表达式如此强大的原因——它们是描述大量潜在变体的简洁方式。"
84
85 #: ../../../__w/calibre/calibre/manual/regexp.rst:34
86 msgid ""
87 "I'm using string here in the sense it is used in programming languages: a "
88 "string of one or more characters, characters including actual characters, "
89 "numbers, punctuation and so-called whitespace (linebreaks, tabulators etc.)."
90 " Please note that generally, uppercase and lowercase characters are not "
91 "considered the same, thus \"a\" being a different character from \"A\" and "
92 "so forth. In calibre, regular expressions are case insensitive in the Search"
93 " bar, but not in the conversion options. There's a way to make every regular"
94 " expression case insensitive, but we'll discuss that later. It gets "
95 "complicated because regular expressions allow for variations in the strings "
96 "it matches, so one expression can match multiple strings, which is why "
97 "people bother using them at all. More on that in a bit."
98 msgstr "我在这里使用的字符串是在编程语言中使用的意义上的:由一个或多个字符组成的字符串,字符包括实际字符、数字、标点符号和所谓的空白(换行符、制表符等)。 请注意,一般情况下,大写和小写字符不被视为相同,因此“a”与“A”是不同的字符,依此类推。 在 calibre 中,正则表达式在搜索栏中不区分大小写,但在转换选项中则不区分大小写。 有一种方法可以使每个正则表达式不区分大小写,但我们稍后会讨论。 它变得很复杂,因为正则表达式允许其匹配的字符串存在变化,因此一个表达式可以匹配多个字符串,这就是人们费心使用它们的原因。 稍后会详细介绍。"
99
100 #: ../../../__w/calibre/calibre/manual/regexp.rst:37
101 msgid "Care to explain?"
102 msgstr "介意解释一下吗?"
103
104 #: ../../../__w/calibre/calibre/manual/regexp.rst:39
105 msgid ""
106 "Well, that's why we're here. First, this is the most important concept in "
107 "regular expressions: *A string by itself is a regular expression that "
108 "matches itself*. That is to say, if I wanted to match the string ``\"Hello, "
109 "World!\"`` using a regular expression, the regular expression to use would "
110 "be ``Hello, World!``. And yes, it really is that simple. You'll notice, "
111 "though, that this *only* matches the exact string ``\"Hello, World!\"``, not"
112 " e.g. ``\"Hello, wOrld!\"`` or ``\"hello, world!\"`` or any other such "
113 "variation."
114 msgstr "嗯,这就是我们在这里的原因。 首先,这是正则表达式中最重要的概念:*字符串本身就是一个与自身匹配的正则表达式*。 也就是说,如果我想使用正则表达式来匹配字符串“Hello, World!”,则使用的正则表达式将是“Hello, World!”。 是的,确实就是这么简单。 不过,您会注意到,这 *仅* 匹配确切的字符串 ``\"Hello, World!\"``,而不是例如 “你好,世界!”或“你好,世界!”或任何其他类似的变体。"
115
116 #: ../../../__w/calibre/calibre/manual/regexp.rst:42
117 msgid "That doesn't sound too bad. What's next?"
118 msgstr "听起来还不错。 下一步是什么?"
119
120 #: ../../../__w/calibre/calibre/manual/regexp.rst:44
121 msgid ""
122 "Next is the beginning of the really good stuff. Remember where I said that "
123 "regular expressions can match multiple strings? This is where it gets a "
124 "little more complicated. Say, as a somewhat more practical exercise, the "
125 "e-book you wanted to convert had a nasty footer counting the pages, like "
126 "\"Page 5 of 423\". Obviously the page number would rise from 1 to 423, thus "
127 "you'd have to match 423 different strings, right? Wrong, actually: regular "
128 "expressions allow you to define sets of characters that are matched: To "
129 "define a set, you put all the characters you want to be in the set into "
130 "square brackets. So, for example, the set ``[abc]`` would match either the "
131 "character \"a\", \"b\" or \"c\". *Sets will always only match one of the "
132 "characters in the set*. They \"understand\" character ranges, that is, if "
133 "you wanted to match all the lower case characters, you'd use the set "
134 "``[a-z]`` for lower- and uppercase characters you'd use ``[a-zA-Z]`` and so "
135 "on. Got the idea? So, obviously, using the expression ``Page [0-9] of 423`` "
136 "you'd be able to match the first 9 pages, thus reducing the expressions "
137 "needed to three: The second expression ``Page [0-9][0-9] of 423`` would "
138 "match all two-digit page numbers, and I'm sure you can guess what the third "
139 "expression would look like. Yes, go ahead. Write it down."
140 msgstr "接下来是真正好东西的开始。 还记得我说过正则表达式可以匹配多个字符串吗? 这就是事情变得有点复杂的地方。 假设,作为一个更实际的练习,您想要转换的电子书有一个讨厌的页脚来计算页数,例如“第 5 页,共 423 页”。 显然页码将从 1 增加到 423,因此您必须匹配 423 个不同的字符串,对吧? 实际上是错误的:正则表达式允许您定义匹配的字符集:要定义一个集合,您可以将想要包含在该集合中的所有字符放入方括号中。因此,例如,集合“[abc]”将匹配字符“a”、“b”或“c”。 *集合将始终仅匹配集合中的一个字符*。 它们“理解”字符范围,也就是说,如果您想匹配所有小写字符,您可以使用集合“[a-z]”来表示小写和大写字符,您可以使用“[a-zA” -Z]``等等。明白了吗? 因此,显然,使用表达式“Page [0-9] of 423”,您可以匹配前 9 页,从而将所需的表达式减少到三个:第二个表达式“Page [0-9]” [0-9] of 423`` 将匹配所有两位数页码,我相信您可以猜到第三个表达式会是什么样子。 好,去吧。 写下来。"
141
142 #: ../../../__w/calibre/calibre/manual/regexp.rst:47
143 msgid "Hey, neat! This is starting to make sense!"
144 msgstr "嘿,整洁!这开始有意义了!"
145
146 #: ../../../__w/calibre/calibre/manual/regexp.rst:49
147 msgid ""
148 "I was hoping you'd say that. But brace yourself, now it gets even better! We"
149 " just saw that using sets, we could match one of several characters at once."
150 " But you can even repeat a character or set, reducing the number of "
151 "expressions needed to handle the above page number example to one. Yes, ONE!"
152 " Excited? You should be! It works like this: Some so-called special "
153 "characters, \"+\", \"?\" and \"*\", *repeat the single element preceding "
154 "them*. (Element means either a single character, a character set, an escape "
155 "sequence or a group (we'll learn about those last two later)- in short, any "
156 "single entity in a regular expression). These characters are called "
157 "wildcards or quantifiers. To be more precise, \"?\" matches *0 or 1* of the "
158 "preceding element, \"*\" matches *0 or more* of the preceding element and "
159 "\"+\" matches *1 or more* of the preceding element. A few examples: The "
160 "expression ``a?`` would match either \"\" (which is the empty string, not "
161 "strictly useful in this case) or \"a\", the expression ``a*`` would match "
162 "\"\", \"a\", \"aa\" or any number of a's in a row, and, finally, the "
163 "expression ``a+`` would match \"a\", \"aa\" or any number of a's in a row "
164 "(Note: it wouldn't match the empty string!). Same deal for sets: The "
165 "expression ``[0-9]+`` would match *every integer number there is*! I know "
166 "what you're thinking, and you're right: If you use that in the above case of"
167 " matching page numbers, wouldn't that be the single one expression to match "
168 "all the page numbers? Yes, the expression ``Page [0-9]+ of 423`` would match"
169 " every page number in that book!"
170 msgstr "我本来希望你会这么说。 但请做好准备,现在情况会变得更好! 我们刚刚看到,使用集合,我们可以一次匹配多个字符之一。 但您甚至可以重复一个字符或集合,将处理上述页码示例所需的表达式数量减少到一个。 是的,一个! 兴奋的? 你应该! 它的工作原理是这样的:一些所谓的特殊字符,“+”,“?” 和“*”,*重复它们前面的单个元素*。 (元素意味着单个字符、字符集、转义序列或组(稍后我们将了解最后两个)——简而言之,正则表达式中的任何单个实体)。 这些字符称为通配符或量词。更准确地说,“?” 匹配前面元素的 *0 或 1*,“*”匹配前面元素的 *0 或更多*,“+”匹配前面元素的 *1 或更多*。 几个例子:表达式 ``a?`` 将匹配 \"\" (这是空字符串,在这种情况下严格来说没有用)或 \"a\",表达式 ``a*`` 将匹配 \"\", \" a\"、\"aa\" 或任意数量的连续 a,最后,表达式 ``a+`` 将匹配 \"a\"、\"aa\" 或任意数量的连续 a(注意:它不会 匹配空字符串!)。对于集合来说也是如此:表达式“[0-9]+”将匹配*每个整数*! 我知道您在想什么,您是对的:如果您在上述匹配页码的情况下使用它,那不是可以匹配所有页码的单个表达式吗? 是的,表达式“第 [0-9]+ 页,共 423 页”将匹配该书中的每个页码!"
171
172 #: ../../../__w/calibre/calibre/manual/regexp.rst:52
173 msgid ""
174 "A note on these quantifiers: They generally try to match as much text as "
175 "possible, so be careful when using them. This is called \"greedy "
176 "behaviour\"- I'm sure you get why. It gets problematic when you, say, try to"
177 " match a tag. Consider, for example, the string ``\"<p "
178 "class=\"calibre2\">Title here</p>\"`` and let's say you'd want to match the "
179 "opening tag (the part between the first pair of angle brackets, a little "
180 "more on tags later). You'd think that the expression ``<p.*>`` would match "
181 "that tag, but actually, it matches the whole string! (The character \".\" is"
182 " another special character. It matches anything *except* linebreaks, so, "
183 "basically, the expression ``.*`` would match any single line you can think "
184 "of). Instead, try using ``<p.*?>`` which makes the quantifier ``\"*\"`` non-"
185 "greedy. That expression would only match the first opening tag, as intended."
186 " There's actually another way to accomplish this: The expression "
187 "``<p[^>]*>`` will match that same opening tag- you'll see why after the next"
188 " section. Just note that there quite frequently is more than one way to "
189 "write a regular expression."
190 msgstr "关于这些量词的注释:它们通常会尝试匹配尽可能多的文本,因此使用它们时要小心。 这就是所谓的“贪婪行为”——我相信你明白为什么。 例如,当您尝试匹配标签时,就会出现问题。例如,考虑字符串 ``\"<p class=\"calibre2\"> Title here </p>\"`` ,假设您想要匹配开始标签(第一对尖括号之间的部分,稍后会详细介绍标签)。 您可能认为表达式 ``<p.*>`` 会匹配该标签,但实际上,它匹配整个字符串! (字符“.”是另一个特殊字符。它匹配*除*换行符之外的任何内容,因此,基本上,表达式“.*”将匹配您能想到的任何单行)。相反,尝试使用 ``<p.*?>`` 这使得量词 ``\"*\"`` 非贪婪。 正如预期的那样,该表达式仅匹配第一个开始标记。 实际上还有另一种方法可以实现此目的:表达式 ``<p[^>]*>`` 将匹配相同的开始 标记 - 您将在下一节之后看到原因。 请注意,编写正则表达式的方法通常不止一种。"
191
192 #: ../../../__w/calibre/calibre/manual/regexp.rst:56
193 msgid ""
194 "Well, these special characters are very neat and all, but what if I wanted "
195 "to match a dot or a question mark?"
196 msgstr "嗯,这些特殊字符非常整齐,但是如果我想匹配一个点或一个问号怎么办?"
197
198 #: ../../../__w/calibre/calibre/manual/regexp.rst:58
199 msgid ""
200 "You can of course do that: Just put a backslash in front of any special "
201 "character and it is interpreted as the literal character, without any "
202 "special meaning. This pair of a backslash followed by a single character is "
203 "called an escape sequence, and the act of putting a backslash in front of a "
204 "special character is called escaping that character. An escape sequence is "
205 "interpreted as a single element. There are of course escape sequences that "
206 "do more than just escaping special characters, for example ``\"\\t\"`` means"
207 " a tabulator. We'll get to some of the escape sequences later. Oh, and by "
208 "the way, concerning those special characters: Consider any character we "
209 "discuss in this introduction as having some function to be special and thus "
210 "needing to be escaped if you want the literal character."
211 msgstr "您当然可以这样做:只需在任何特殊字符前面放置一个反斜杠,它就会被解释为文字字符,没有任何特殊含义。 这对反斜杠后跟一个字符称为转义序列,将反斜杠放在特殊字符前面的行为称为转义该字符。 转义序列被解释为单个元素。 当然,有些转义序列的作用不仅仅是转义特殊字符,例如“”\\t“表示制表符。 稍后我们将讨论一些转义序列。 哦,顺便说一下,关于那些特殊字符:将我们在本介绍中讨论的任何字符视为具有某些特殊功能,因此如果您想要字面字符,则需要对其进行转义。"
212
213 #: ../../../__w/calibre/calibre/manual/regexp.rst:61
214 msgid "So, what are the most useful sets?"
215 msgstr "那么,最有用的集合是什么?"
216
217 #: ../../../__w/calibre/calibre/manual/regexp.rst:63
218 msgid ""
219 "Knew you'd ask. Some useful sets are ``[0-9]`` matching a single number, "
220 "``[a-z]`` matching a single lowercase letter, ``[A-Z]`` matching a single "
221 "uppercase letter, ``[a-zA-Z]`` matching a single letter and ``[a-zA-Z0-9]`` "
222 "matching a single letter or number. You can also use an escape sequence as "
223 "shorthand:"
224 msgstr "就知道你会问。 一些有用的集合是“[0-9]”匹配单个数字,“[a-z]”匹配单个小写字母,“[A-Z]”匹配单个大写字母,“[a-zA” -Z]`` 匹配单个字母,``[a-zA-Z0-9]`` 匹配单个字母或数字。 您还可以使用转义序列作为简写:"
225
226 #: ../../../__w/calibre/calibre/manual/regexp.rst:69
227 msgid "``\\d``"
228 msgstr "``\\d``"
229
230 #: ../../../__w/calibre/calibre/manual/regexp.rst:70
231 msgid "is equivalent to ``[0-9]``"
232 msgstr "相当于``[0-9]``"
233
234 #: ../../../__w/calibre/calibre/manual/regexp.rst:72
235 msgid "``\\w``"
236 msgstr "``\\w``"
237
238 #: ../../../__w/calibre/calibre/manual/regexp.rst:73
239 msgid "is equivalent to ``[a-zA-Z0-9_]``"
240 msgstr "相当于``[a-zA-Z0-9_]``"
241
242 #: ../../../__w/calibre/calibre/manual/regexp.rst:76
243 msgid "``\\s``"
244 msgstr "``\\s``"
245
246 #: ../../../__w/calibre/calibre/manual/regexp.rst:77
247 msgid "is equivalent to any whitespace"
248 msgstr "相当于任何空白"
249
250 #: ../../../__w/calibre/calibre/manual/regexp.rst:80
251 msgid ""
252 "\"Whitespace\" is a term for anything that won't be printed. These "
253 "characters include space, tabulator, line feed, form feed, carriage return, "
254 "non-breaking spaces, etc."
255 msgstr "“空白”是一个术语,指的是任何不会被打印的内容。 这些字符包括空格、制表符、换行符、换页符、回车符、不间断空格等。"
256
257 #: ../../../__w/calibre/calibre/manual/regexp.rst:83
258 msgid ""
259 "The upper and lower case sets may match both upper and lowercase if the "
260 "setting to make searches case insensitive is enabled. Such settings are "
261 "found, for instance in Preferences->Searching in calibre itself and on the "
262 "Search panel in the calibre :guilabel:`E-book viewer` as well as the calibre"
263 " :guilabel:`Edit book` tool."
264 msgstr "如果启用了搜索不区分大小写的设置,则大写和小写集可能会同时匹配大写和小写。 例如,可以在 calibre 本身的“首选项”->“搜索”以及 calibre“电子书阅读器”以及 calibre“编辑书籍”工具的搜索面板中找到此类设置。"
265
266 #: ../../../__w/calibre/calibre/manual/regexp.rst:89
267 msgid ""
268 "As a last note on sets, you can also define a set as any character *but* "
269 "those in the set. You do that by including the character ``\"^\"`` as the "
270 "*very first character in the set*. Thus, ``[^a]`` would match any character "
271 "excluding \"a\". That's called complementing the set. Those escape sequence "
272 "shorthands we saw earlier can also be complemented: ``\"\\D\"`` means any "
273 "non-number character, thus being equivalent to ``[^0-9]``. The other "
274 "shorthands can be complemented by, you guessed it, using the respective "
275 "uppercase letter instead of the lowercase one. So, going back to the example"
276 " ``<p[^>]*>`` from the previous section, now you can see that the character "
277 "set it's using tries to match any character except for a closing angle "
278 "bracket."
279 msgstr "作为集合的最后一个注释,您还可以将集合定义为集合中的任何字符*但*字符。 您可以通过将字符 ``\"^\"`` 作为*集合中的第一个字符*来实现这一点。 因此,``[^a]`` 将匹配除“a”之外的任何字符。 这就是所谓的补充集合。 我们之前看到的那些转义序列简写也可以补充:``“\\D”``表示任何非数字字符,因此相当于``[^0-9]``。 您猜对了,可以使用相应的大写字母而不是小写字母来补充其他简写。 因此,回到上一节中的示例 ``<p[^>]*>`` ,现在您可以看到它使用的字符集尝试匹配除右尖括号之外的任何字符。"
280
281 #: ../../../__w/calibre/calibre/manual/regexp.rst:94
282 msgid ""
283 "But if I had a few varying strings I wanted to match, things get "
284 "complicated?"
285 msgstr "但是如果我想要匹配一些不同的字符串,事情会变得复杂吗?"
286
287 #: ../../../__w/calibre/calibre/manual/regexp.rst:96
288 msgid ""
289 "Fear not, life still is good and easy. Consider this example: The book "
290 "you're converting has \"Title\" written on every odd page and \"Author\" "
291 "written on every even page. Looks great in print, right? But in e-books, "
292 "it's annoying. You can group whole expressions in normal parentheses, and "
293 "the character ``\"|\"`` will let you match *either* the expression to its "
294 "right *or* the one to its left. Combine those and you're done. Too fast for "
295 "you? Okay, first off, we group the expressions for odd and even pages, thus "
296 "getting ``(Title)(Author)`` as our two needed expressions. Now we make "
297 "things simpler by using the vertical bar (``\"|\"`` is called the vertical "
298 "bar character): If you use the expression ``(Title|Author)`` you'll either "
299 "get a match for \"Title\" (on the odd pages) or you'd match \"Author\" (on "
300 "the even pages). Well, wasn't that easy?"
301 msgstr "不要害怕,生活仍然美好而轻松。 考虑以下示例:您要转换的书籍的每个奇数页上都写有“标题”,而每个偶数页上都写有“作者”。 印刷版看起来很棒,对吧? 但在电子书中,这很烦人。 您可以将整个表达式分组在普通括号中,并且字符 ``\"|\"`` 将让您匹配*其右侧的表达式*或*其左侧的表达式。 将它们结合起来就完成了。 对你来说太快了吗? 好的,首先,我们将奇数页和偶数页的表达式分组,从而将“(标题)( 作者 )”作为我们需要的两个表达式。 现在我们通过使用竖线(``“|”``称为竖线字符)使事情变得更简单:如果您使用表达式``(标题 | 作者)``,您将获得“Title”的匹配项 ”(在奇数页上),或者匹配“作者”(在偶数页上)。 嗯,这不是很容易吗?"
302
303 #: ../../../__w/calibre/calibre/manual/regexp.rst:98
304 msgid ""
305 "You can, of course, use the vertical bar without using grouping parentheses,"
306 " as well. Remember when I said that quantifiers repeat the element preceding"
307 " them? Well, the vertical bar works a little differently: The expression "
308 "\"Title|Author\" will also match either the string \"Title\" or the string "
309 "\"Author\", just as the above example using grouping. *The vertical bar "
310 "selects between the entire expression preceding and following it*. So, if "
311 "you wanted to match the strings \"Calibre\" and \"calibre\" and wanted to "
312 "select only between the upper- and lowercase \"c\", you'd have to use the "
313 "expression ``(c|C)alibre``, where the grouping ensures that only the \"c\" "
314 "will be selected. If you were to use ``c|Calibre``, you'd get a match on the"
315 " string \"c\" or on the string \"Calibre\", which isn't what we wanted. In "
316 "short: If in doubt, use grouping together with the vertical bar."
317 msgstr "当然,您也可以使用竖线而不使用分组括号。 还记得我说过量词会重复它们前面的元素吗? 嗯,竖线的工作方式有点不同:表达式“ Title | 作者”也将匹配字符串“Title”或字符串“作者”,就像上面使用分组的示例一样。 *竖线在其前后的整个表达式之间进行选择*。 因此,如果您想匹配字符串“Calibre”和“calibre”,并且只想在大写和小写“c”之间进行选择,则必须使用表达式“(c|C)alibre”, 其中分组确保仅选择“c”。 如果你要使用“c|Calibre”,你会得到字符串“c”或字符串“Calibre”的匹配,这不是我们想要的。 简而言之:如果有疑问,请与竖线一起使用分组。"
318
319 #: ../../../__w/calibre/calibre/manual/regexp.rst:101
320 msgid "You missed..."
321 msgstr "你错过了。。。"
322
323 #: ../../../__w/calibre/calibre/manual/regexp.rst:103
324 msgid ""
325 "... wait just a minute, there's one last, really neat thing you can do with "
326 "groups. If you have a group that you previously matched, you can use "
327 "references to that group later in the expression: Groups are numbered "
328 "starting with 1, and you reference them by escaping the number of the group "
329 "you want to reference, thus, the fifth group would be referenced as ``\\5``."
330 " So, if you searched for ``([^ ]+) \\1`` in the string \"Test Test\", you'd "
331 "match the whole string!"
332 msgstr "...等一下,还有最后一件非常巧妙的事情,你可以与团体一起做。 如果您之前有一个匹配的组,则可以稍后在表达式中使用对该组的引用:组的编号从 1 开始,您可以通过转义要引用的组的编号来引用它们,因此是第五组 将被引用为``\\5``。 因此,如果您在字符串“Test Test”中搜索``([^]+) \\1``,您将匹配整个字符串!"
333
334 #: ../../../__w/calibre/calibre/manual/regexp.rst:107
335 msgid ""
336 "In the beginning, you said there was a way to make a regular expression case"
337 " insensitive?"
338 msgstr "一开始,你说有办法让正则表达式不区分大小写?"
339
340 #: ../../../__w/calibre/calibre/manual/regexp.rst:109
341 msgid ""
342 "Yes, I did, thanks for paying attention and reminding me. You can tell "
343 "calibre how you want certain things handled by using something called flags."
344 " You include flags in your expression by using the special construct "
345 "``(?flags go here)`` where, obviously, you'd replace \"flags go here\" with "
346 "the specific flags you want. For ignoring case, the flag is ``i``, thus you "
347 "include ``(?i)`` in your expression. Thus, ``(?i)test`` would match "
348 "\"Test\", \"tEst\", \"TEst\" and any case variation you could think of."
349 msgstr "是的,我知道了,谢谢你的关注和提醒。 您可以使用称为标志的东西来告诉 calibre 您希望如何处理某些事情。 您可以通过使用特殊构造“(?flags go here)”在表达式中包含标志,显然,您可以将“flags go here”替换为您想要的特定标志。 为了忽略大小写,标志是“i”,因此您可以在表达式中包含“(?i)”。 因此,``(?i)test`` 将匹配“Test”、“tEst”、“TEst”以及您能想到的任何大小写变体。"
350
351 #: ../../../__w/calibre/calibre/manual/regexp.rst:111
352 msgid ""
353 "Another useful flag lets the dot match any character at all, *including* the"
354 " newline, the flag ``s``. If you want to use multiple flags in an "
355 "expression, just put them in the same statement: ``(?is)`` would ignore case"
356 " and make the dot match all. It doesn't matter which flag you state first, "
357 "``(?si)`` would be equivalent to the above."
358 msgstr "另一个有用的标志可以让点匹配任何字符,*包括*换行符,标志“s”。 如果您想在表达式中使用多个标志,只需将它们放在同一个语句中即可:``(?is)`` 将忽略大小写并使点全部匹配。 无论您首先声明哪个标志,``(?si)`` 都等同于上面的。"
359
360 #: ../../../__w/calibre/calibre/manual/regexp.rst:114
361 msgid ""
362 "I think I'm beginning to understand these regular expressions now... how do "
363 "I use them in calibre?"
364 msgstr "我想我现在开始理解这些正则表达式了......我如何在 calibre 中使用它们?"
365
366 #: ../../../__w/calibre/calibre/manual/regexp.rst:117
367 msgid "Conversions"
368 msgstr "转换"
369
370 #: ../../../__w/calibre/calibre/manual/regexp.rst:119
371 msgid ""
372 "Let's begin with the conversion settings, which is really neat. In the "
373 ":guilabel:`Search & replace` part, you can input a regexp (short for regular"
374 " expression) that describes the string that will be replaced during the "
375 "conversion. The neat part is the wizard. Click on the wizard staff and you "
376 "get a preview of what calibre \"sees\" during the conversion process. Scroll"
377 " down to the string you want to remove, select and copy it, paste it into "
378 "the regexp field on top of the window. If there are variable parts, like "
379 "page numbers or so, use sets and quantifiers to cover those, and while "
380 "you're at it, remember to escape special characters, if there are some. Hit "
381 "the button labeled :guilabel:`Test` and calibre highlights the parts it "
382 "would replace were you to use the regexp. Once you're satisfied, hit OK and "
383 "convert. Be careful if your conversion source has tags like this example::"
384 msgstr "让我们从转换设置开始,这真的很简洁。 在“搜索和替换”部分中,您可以输入一个regexp(正则表达式的缩写)来描述转换过程中将被替换的字符串。 最巧妙的部分是向导。 单击向导人员,您可以预览转换过程中口径“看到”的内容。 向下滚动到要删除的字符串,选择并复制它,将其粘贴到窗口顶部的正则表达式字段中。 如果存在可变部分,例如页码等,请使用集合和量词来覆盖这些部分,并且在使用时,请记住转义特殊字符(如果有)。 点击标有“测试”的按钮,口径会突出显示如果您使用正则表达式它将替换的部分。 一旦您满意,请点击“确定”并进行转换。 如果您的转化源具有类似以下示例的标签,请务必小心:"
385
386 #: ../../../__w/calibre/calibre/manual/regexp.rst:129
387 msgid ""
388 "(shamelessly ripped out of `this thread "
389 "<https://www.mobileread.com/forums/showthread.php?t=75594\">`_). You'd have "
390 "to remove some of the tags as well. In this example, I'd recommend beginning"
391 " with the tag ``<b class=\"calibre2\">``, now you have to end with the "
392 "corresponding closing tag (opening tags are ``<tag>``, closing tags are "
393 "``</tag>``), which is simply the next ``</b>`` in this case. (Refer to a "
394 "good HTML manual or ask in the forum if you are unclear on this point). The "
395 "opening tag can be described using ``<b.*?>``, the closing tag using "
396 "``</b>``, thus we could remove everything between those tags using "
397 "``<b.*?>.*?</b>``. But using this expression would be a bad idea, because it"
398 " removes everything enclosed by <b>- tags (which, by the way, render the "
399 "enclosed text in bold print), and it's a fair bet that we'll remove portions"
400 " of the book in this way. Instead, include the beginning of the enclosed "
401 "string as well, making the regular expression "
402 "``<b.*?>\\s*Generated\\s+by\\s+ABC\\s+Amber\\s+LIT.*?</b>`` The ``\\s`` with"
403 " quantifiers are included here instead of explicitly using the spaces as "
404 "seen in the string to catch any variations of the string that might occur. "
405 "Remember to check what calibre will remove to make sure you don't remove any"
406 " portions you want to keep if you test a new expression. If you only check "
407 "one occurrence, you might miss a mismatch somewhere else in the text. Also "
408 "note that should you accidentally remove more or fewer tags than you "
409 "actually wanted to, calibre tries to repair the damaged code after doing the"
410 " removal."
411 msgstr "(无耻地从“这个线程 <https://www.mobileread.com/forums/showthread.php?t=75594\">`_ )中撕下来。您还必须删除一些标签。在此示例中 ,我建议以标签``<b class=\"calibre2\">``开始,现在你必须以相应的结束标签结束(开始标签是``<tag>``,结束标签是``</tag>``),在这种情况下这只是下一个``</b>`` 。(如果您对此不清楚,请参阅较好的 HTML 手册或在论坛中询问)。开始标记可以使用 ``<b.*?>`` 来描述,结束标记可以使用 ``</b>``,因此我们可以使用 ``<b.*?>.*?</b>`` 删除这些标签之间的所有内容。但是使用这个表达式将是一个坏主意,因为它删除了 <b>- 标签包含的所有内容(顺便说一句,以粗体显示所包含的文本),并且我们很可能会以这种方式删除本书的部分内容。相反,也包括所包含字符串的开头,使正则表达式``<b.* ?>\\s*Generate\\s+by\\s+ABC\\s+Amber\\s+LIT.*?</b>`` 带有量词的 ``\\s`` 包含在此处,而不是像字符串中那样显式使用空格 捕获可能出现的字符串的任何变化。 请记住检查要删除的口径,以确保在测试新表达式时不会删除任何想要保留的部分。 如果您只检查一次出现的情况,则可能会错过文本中其他地方的不匹配之处。 另请注意,如果您不小心删除了比您实际想要的更多或更少的标签,calibre 会在删除后尝试修复损坏的代码。"
412
413 #: ../../../__w/calibre/calibre/manual/regexp.rst:132
414 msgid "Adding books"
415 msgstr "添加书籍"
416
417 #: ../../../__w/calibre/calibre/manual/regexp.rst:134
418 msgid ""
419 "Another thing you can use regular expressions for is to extract metadata "
420 "from filenames. You can find this feature in the \"Adding books\" part of "
421 "the settings. There's a special feature here: You can use field names for "
422 "metadata fields, for example ``(?P<title>)`` would indicate that calibre "
423 "uses this part of the string as book title. The allowed field names are "
424 "listed in the windows, together with another nice test field. An example: "
425 "Say you want to import a whole bunch of files named like ``Classical Texts: "
426 "The Divine Comedy by Dante Alighieri.mobi``. (Obviously, this is already in "
427 "your library, since we all love classical Italian poetry) or ``Science "
428 "Fiction epics: The Foundation Trilogy by Isaac Asimov.epub``. This is "
429 "obviously a naming scheme that calibre won't extract any meaningful data out"
430 " of - its standard expression for extracting metadata is ``(?P<title>.+) - "
431 "(?P<author>[^_]+)``. A regular expression that works here would be "
432 "``[a-zA-Z]+: (?P<title>.+) by (?P<author>.+)``. Please note that, inside the"
433 " group for the metadata field, you need to use expressions to describe what "
434 "the field actually matches. And also note that, when using the test field "
435 "calibre provides, you need to add the file extension to your testing "
436 "filename, otherwise you won't get any matches at all, despite using a "
437 "working expression."
438 msgstr "您可以使用正则表达式的另一件事是从文件名中提取元数据。 您可以在设置的“添加图书”部分找到此功能。 这里有一个特殊功能:您可以使用元数据字段的字段名称,例如“(?P<title>)”将表明 calibre 使用这部分字符串作为书名。 窗口中列出了允许的字段名称,以及另一个不错的测试字段。举个例子:假设您要导入一大堆名为“古典文本:但丁·阿利吉耶里的神曲.mobi”的文件。 (显然,这已经在您的书库中,因为我们都喜欢古典意大利诗歌)或“科幻史诗:艾萨克·阿西莫夫的基础三部曲.epub”。 这显然是一个 calibre 不会从中提取任何有意义的数据的命名方案 - 它提取元数据的标准表达式是``(?P<title>.+) - (?P<author>[^_]+)``。此处适用的正则表达式为“[a-zA-Z]+: (?P<title>.+) by (?P<author>.+)”。 请注意,在元数据字段的组内,您需要使用表达式来描述字段实际匹配的内容。 另请注意,在使用 calibre 提供的测试字段时,您需要将文件扩展名添加到测试文件名中,否则即使使用工作表达式,您也根本不会获得任何匹配项。"
439
440 #: ../../../__w/calibre/calibre/manual/regexp.rst:138
441 msgid "Bulk editing metadata"
442 msgstr "批量编辑元数据"
443
444 #: ../../../__w/calibre/calibre/manual/regexp.rst:140
445 msgid ""
446 "The last part is regular expression :guilabel:`Search and replace` in "
447 "metadata fields. You can access this by selecting multiple books in the "
448 "library and using bulk metadata edit. Be very careful when using this last "
449 "feature, as it can do **Very Bad Things** to your library! Double-check that"
450 " your expressions do what you want them to using the test fields, and only "
451 "mark the books you really want to change! In the regular expression search "
452 "mode, you can search in one field, replace the text with something and even "
453 "write the result into another field. A practical example: Say your library "
454 "contained the books of Frank Herbert's Dune series, named after the fashion "
455 "``Dune 1 - Dune``, ``Dune 2 - Dune Messiah`` and so on. Now you want to get "
456 "``Dune`` into the series field. You can do that by searching for ``(.*?) "
457 "\\d+ - .*`` in the title field and replacing it with ``\\1`` in the series "
458 "field. See what I did there? That's a reference to the first group you're "
459 "replacing the series field with. Now that you have the series all set, you "
460 "only need to do another search for ``.*? -`` in the title field and replace "
461 "it with ``\"\"`` (an empty string), again in the title field, and your "
462 "metadata is all neat and tidy. Isn't that great? By the way, instead of "
463 "replacing the entire field, you can also append or prepend to the field, so,"
464 " if you *wanted* the book title to be prepended with series info, you could "
465 "do that as well. As you by now have undoubtedly noticed, there's a checkbox "
466 "labeled :guilabel:`Case sensitive`, so you won't have to use flags to select"
467 " behaviour here."
468 msgstr "最后一部分是元数据字段中的正则表达式“搜索和替换”。 您可以通过选择书库中的多本书并使用批量元数据编辑来访问此内容。 使用最后一个功能时要非常小心,因为它可能会对您的书库造成**非常糟糕的事情**! 使用测试字段仔细检查您的表达式是否符合您的要求,并且仅标记您真正想要更改的书籍! 在正则表达式搜索模式下,您可以在一个字段中搜索,用某些内容替换文本,甚至可以将结果写入另一字段。一个实际的例子:假设您的书库包含弗兰克·赫伯特的《沙丘》系列书籍,以时尚“沙丘 1 - 沙丘”、“沙丘 2 - 沙丘弥赛亚”等命名。 现在你想让《沙丘》进入系列领域。 您可以通过在标题字段中搜索``(.*?) \\d+ - .*`` 并在系列字段中将其替换为``\\1`` 来做到这一点。看看我在那里做了什么? 这是对您要替换系列字段的第一组的引用。 现在您已经完成了该系列的准备,您只需再次搜索``.*? -`` 在标题字段中,并再次在标题字段中将其替换为 ``\"\"`` (空字符串),这样您的元数据就干净整洁了。是不是很棒? 顺便说一句,您也可以附加或添加到该字段,而不是替换整个字段,因此,如果您“希望”在书名前面添加系列信息,您也可以这样做。 您现在无疑已经注意到,有一个标记为“区分大小写”的复选框,因此您不必在此处使用标志来选择行为。"
469
470 #: ../../../__w/calibre/calibre/manual/regexp.rst:142
471 msgid ""
472 "Well, that just about concludes the very short introduction to regular "
473 "expressions. Hopefully I'll have shown you enough to at least get you "
474 "started and to enable you to continue learning by yourself- a good starting "
475 "point would be the `Python documentation for regexps "
476 "<https://docs.python.org/library/re.html>`_."
477 msgstr "好了,关于正则表达式的简短介绍就到此结束了。 希望我能向您展示足够的内容,至少让您入门并让您能够继续自己学习 - 一个很好的起点是“正则表达式的 Python 文档”<https://docs.python.org/library/re.html>`_."
478
479 #: ../../../__w/calibre/calibre/manual/regexp.rst:144
480 msgid ""
481 "One last word of warning, though: Regexps are powerful, but also really easy"
482 " to get wrong. calibre provides really great testing possibilities to see if"
483 " your expressions behave as you expect them to. Use them. Try not to shoot "
484 "yourself in the foot. (God, I love that expression...). But should you, "
485 "despite the warning, injure your foot (or any other body parts), try to "
486 "learn from it."
487 msgstr "不过,最后一句警告是:正则表达式很强大,但也很容易出错。 calibre 提供了非常好的测试可能性,可以查看您的表达式是否按照您的预期运行。 使用它们。 尽量不要搬起石头砸自己的脚。 (上帝,我喜欢这个表达......)。 但是,如果您不顾警告,受伤了您的脚(或任何其他身体部位),请尝试从中吸取教训。"
488
489 #: ../../../__w/calibre/calibre/manual/regexp.rst:148
490 msgid "Quick reference"
491 msgstr "快速参考"
492
493 #: ../../../__w/calibre/calibre/manual/regexp.rst:156
494 msgid "Credits"
495 msgstr "荣誉"
496
497 #: ../../../__w/calibre/calibre/manual/regexp.rst:158
498 msgid "Thanks for helping with tips, corrections and such:"
499 msgstr "感谢您提供提示、更正等帮助:"
500
501 #: ../../../__w/calibre/calibre/manual/regexp.rst:160
502 msgid "ldolse"
503 msgstr "ldolse"
504
505 #: ../../../__w/calibre/calibre/manual/regexp.rst:161
506 msgid "kovidgoyal"
507 msgstr "kovidgoyal"
508
509 #: ../../../__w/calibre/calibre/manual/regexp.rst:162
510 msgid "chaley"
511 msgstr "chaley"
512
513 #: ../../../__w/calibre/calibre/manual/regexp.rst:163
514 msgid "dwanthny"
515 msgstr "dwanthny"
516
517 #: ../../../__w/calibre/calibre/manual/regexp.rst:164
518 msgid "kacir"
519 msgstr "kacir"
520
521 #: ../../../__w/calibre/calibre/manual/regexp.rst:165
522 msgid "Starson17"
523 msgstr "Starson17"
524
525 #: ../../../__w/calibre/calibre/manual/regexp.rst:166
526 msgid "Orpheu"
527 msgstr "Orpheu"
528
529 #: ../../../__w/calibre/calibre/manual/regexp.rst:168
530 msgid ""
531 "For more about regexps see `The Python User Manual "
532 "<https://docs.python.org/library/re.html>`_. The actual regular expression "
533 "library used by calibre is: `regex <https://bitbucket.org/mrabarnett/mrab-"
534 "regex/src/hg/>`_ which supports several useful enhancements over the Python "
535 "standard library one."
536 msgstr "有关正则表达式的更多信息,请参阅“Python 用户手册 <https://docs.python.org/library/re.html>”_。 calibre 使用的实际正则表达式书库是:`regex <https://bitbucket.org/mrabarnett/mrab-regex/src/hg/>`_,它支持对 Python 标准库的一些有用的增强。"