# SOME DESCRIPTIVE TITLE. # Copyright (C) Kovid Goyal # This file is distributed under the same license as the calibre package. # # Translators: # akihiko tanae (tanaeakihiko), 2025-2026 msgid "" msgstr "" "Project-Id-Version: calibre\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-02-22 09:00+0000\n" "PO-Revision-Date: 2014-06-17 08:35+0000\n" "Last-Translator: akihiko tanae (tanaeakihiko), 2025-2026\n" "Language-Team: Japanese (http://app.transifex.com/calibre/calibre/language/ja/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: ja\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../../__w/calibre/calibre/manual/regexp.rst:4 msgid "All about using regular expressions in calibre" msgstr "calibre で正規表現を利用するにあたって重要なこと" #: ../../../__w/calibre/calibre/manual/regexp.rst:6 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." msgstr "正規表現は、電子書籍のコンテンツと書誌に対して高度な操作を実行するために calibre のあちこちで使われている機能です。このチュートリアルは、calibre で正規表現を使い始めるための簡単な入門書です。" #: ../../../__w/calibre/calibre/manual/regexp.rst:11 msgid "Contents" msgstr "目次" #: ../../../__w/calibre/calibre/manual/regexp.rst:14 msgid "First, a word of warning and a word of courage" msgstr "最初に、警告と激励" #: ../../../__w/calibre/calibre/manual/regexp.rst:16 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." msgstr "必然的に、これは技術的なものになります。何と言っても正規表現というものは、技術的なことを行うための技術的なツールなのです。使わざるを得ない専門用語や概念が、複雑または難解に見えるかもしれません。そうした概念について、可能な限りわかりやすく説明していくつもりですが、専門用語をまったく使わずに説明するのは無理があります。そうは言っても、専門用語を見てもがっかりしないでください。新しいことはすべて説明するよう努めました。そして正規表現そのものがあやしげな黒魔術のように見えるかもしれませんが (もっとぶっちゃけると、わけのわからないランダムな文字と記号の羅列にしか見えないかもしれませんが) 決してそれほど複雑なものではありません。正規表現をきちんと理解している人でも複雑なものを解読するのは困難ですが、書くのはそれほど難しいことではありません。一歩ずつ段階的に構築していけばよいのです。ですから、一緒に最初の一歩を踏み出してみましょう。" #: ../../../__w/calibre/calibre/manual/regexp.rst:19 msgid "Where in calibre can you use regular expressions?" msgstr "calibre のどこで正規表現を使えますか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:21 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 :guilabel:`Search and replace` feature. Finally, you can " "use regular expressions when searching the calibre book list and when " "searching inside the calibre E-book viewer." msgstr "calibre が正規表現を使用する場所はいくつかあります。それは変換オプションの中の :guilabel:`検索 & 置換` 、インポート設定の中にあるファイル名からの書誌の検出、書誌を一括編集するときの検索 & 置換です。calibre の書籍エディタは、:guilabel:`検索と置換` 機能の中で正規表現を使用することができます。最後に、calibre の本の一覧を検索するときや calibre の電子書籍ビューアの中で検索をするときにも正規表現を使用できます。" #: ../../../__w/calibre/calibre/manual/regexp.rst:30 msgid "What on earth *is* a regular expression?" msgstr "正規表現とはいったい何ですか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:32 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." msgstr "正規表現とは、文字列のセットを表現する方法です。ひとつの正規表現で、いくつもの異なる文字列に *マッチ* させることができます。これが正規表現を非常に強力にしているものです。潜在的に数多くのバリエーションを表現する、簡潔な方法なのです。" #: ../../../__w/calibre/calibre/manual/regexp.rst:34 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." msgstr "ここでは文字列という言葉をプログラミング言語で使用される意味で使っています。文字列とは、ひとつ以上の文字で、実際の文字、数字、句読点、およびいわゆる空白と呼ばれるもの (改行、タブなど) を含みます。通常、大文字と小文字は同じものとはみなされないため、たとえば \"a\" は \"A\" とは別の文字として扱われます。calibre では、検索バーでは正規表現は大文字と小文字を区別しませんが、変換オプションでは区別します。すべての正規表現で大文字と小文字を区別しなくする設定もありますが、それは後で説明します。正規表現はマッチする文字列にバリエーションを許しているために複雑になり、ひとつの表現が複数の文字列にマッチします。人々が正規表現を使用したがらないのは、それが理由です。" #: ../../../__w/calibre/calibre/manual/regexp.rst:37 msgid "Care to explain?" msgstr "説明してもらえますか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:39 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." msgstr "それこそが目的です。まず、正規表現において最も重要な概念ですが、 *ある文字列は、その文字列自体にマッチする正規表現* です。つまり ``\"Hello, World!\"`` という文字列に正規表現を使ってマッチさせたい場合、使用すべき正規表現は ``Hello, World!`` です。そうです、それくらい簡単なことなのです。ただし、これがマッチするのは ``\"Hello, World!\"`` という文字列 *だけ* です。つまり、``\"Hello, wOrld!\"`` や ``\"hello, world!\"`` など他のバリエーションにはマッチしません。" #: ../../../__w/calibre/calibre/manual/regexp.rst:42 msgid "That doesn't sound too bad. What's next?" msgstr "そんなに悪くありません。次は?" #: ../../../__w/calibre/calibre/manual/regexp.rst:44 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." msgstr "次は、本当に使えるもののさわりの部分です。正規表現が複数の文字列にマッチする可能性があると説明したのを覚えていますか? これが少し複雑になっていくところです。たとえば、もっと実用的な例として、変換したい電子書籍のフッタ部分に \"Page 5 of 423\" のように厄介なページカウントがあったとします。明らかにページ数は 1 から 423 まで順に増えていきますから、423 通りの異なる文字列にマッチさせる必要があります。そうでしょう? しかし、実は必要ないのです。正規表現を使えば、マッチする文字のセットを定義することが可能です。セットを定義するには、マッチさせたいすべての文字を角カッコの中に羅列します。したがってたとえば ``[abc]`` というセットは \"a\", \"b\" または \"c\" という文字にマッチします。*セットは、常にセット内の文字のひとつとだけマッチします*。セットは文字の範囲を \"理解\" します。つまり、すべての小文字とマッチさせたい場合には ``[a-z]`` を使用し、小文字と大文字にマッチさせたい場合には ``[a-zA-Z]`` を使用するといった具合です。理解できましたか? したがって ``Page [0-9] of 423`` という表現を使用すれば、言うまでもなく最初の 9 ページにマッチさせることができます。こうして必要な表現を 3 個に絞ることができます。2 個目の表現は ``Page [0-9][0-9] of 423`` で、すべての 2 桁のページにマッチします。3 個目の表現をどうすればよいかは、もうおわかりですね。はい、どうぞ。書いてみてください。" #: ../../../__w/calibre/calibre/manual/regexp.rst:47 msgid "Hey, neat! This is starting to make sense!" msgstr "すごい! 意味がわかってきました!" #: ../../../__w/calibre/calibre/manual/regexp.rst:49 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!" msgstr "そう言ってくれると思っていました。でも気を引き締めてください。まだまだよくなって行きます。セットを使用すると、いくつかの文字を一度にマッチさせることができることがわかりました。しかし文字やセットを繰り返すことも可能なのです。そうすることで、上の例でページ番号を扱う正規表現をひとつに減らすことができます。そうです、たったの 1 個です。わくわくしますか? きっとするでしょう。それは次のように機能します: 特殊文字と呼ばれるもの一部、\"+\", \"?\" および \"*\" は *それに続くひとつの要素を繰り返します* 。(要素とは、ひとつも文字、ひとつの文字セット、エスケープシーケンス、またはグループのことです。最後の 2 つについては後で説明します。要するに、正規表現の中にある任意のひとつのエンティティです) このような文字は、ワイルドカードまたは量指定子と呼ばれます。具体的に言うと、\"?\" は直前の要素が *0 または 1* 個のものにマッチし、\"*\" は直前の要素が *0 個以上* のものにマッチし、\"+\" は直前の要素が *1 個以上* のものにマッチします。いくつか例を示しましょう。正規表現 ``a?`` は \"\" (つまり空の文字列で、このケースでは特に便利ではありません) または \"a\" にマッチし、``a*`` は \"\", \"a\", \"aa\", および a が連続して並んでいる限り何個でもマッチし、正規表現 ``a+`` は \"a\", \"aa\", および a が連続して並んでいる限り何個でもマッチします (ただし空の文字列にはマッチしません)。セットについても同じことが言えます。正規表現 ``[0-9]+`` は *すべての整数* にマッチします。さてここで、読者が何を考えているか筆者にはわかります。そしてそれは間違っていません。もしこれを上記のケースでページ番号のマッチに使用したら、ひとつの正規表現だけですべてのページにマッチするのではないか? そのとおり、``Page [0-9]+ of 423`` は本の中のすべてのページにマッチするでしょう。" #: ../../../__w/calibre/calibre/manual/regexp.rst:52 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 ``\"

Title here

\"`` 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 ```` 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 ```` 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 " "``]*>`` 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." msgstr "量指定子に関する注意点: 量指定子は通常、可能な限り多くのテキストとマッチさせようとします。ですから使用する場合には注意してください。これは \"貪欲な動作\" と呼ばれます。もちろん理由はおわかりですね。これは、たとえばタグをマッチさせようとする場合などに問題が起きます。たとえば、文字列 ``\"

Title here

\"`` から開きタグ (山カッコで囲まれた最初のパーツ、タグについては後述します) にマッチさせたいとしましょう。正規表現 ```` がそのタグにマッチすると思うかもしれませんが、実際には文字列全体にマッチしてしまいます。(文字 \".\" もまた特殊文字です。これは改行 *以外* のすべての文字にマッチします。したがって、基本的には正規表現 ``.*`` はどのような内容でも 1 行すべてにマッチします) 代わりに ```` を試してみましょう。これは量指定子 ``\"*\"`` を貪欲ではなくします。この正規表現は、意図したとりに最初のタグにだけマッチします。実はこれにはもうひとつ別のやり方があります。正規表現 ``]*>`` も同様に最初の開きタグにマッチします。理由は次の章以降にわかるでしょう。ここでは、しばしば正規表現の書き方はひとつではないということを心に留めておいてください。" #: ../../../__w/calibre/calibre/manual/regexp.rst:56 msgid "" "Well, these special characters are very neat and all, but what if I wanted " "to match a dot or a question mark?" msgstr "特殊文字ってすごいけど、ドットやクエスチョンマークにマッチさせたかったらどうすればいい?" #: ../../../__w/calibre/calibre/manual/regexp.rst:58 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." msgstr "もちろんできます。特殊文字の前にバックスラッシュをつければ、特別な意味のない文字リテラルとして解釈されます。特殊文字の前にバックスラッシュをつけた組み合わせのことを、エスケープシーケンスと呼び、特殊文字の前にバックスラッシュをつけることを文字をエスケープすると言います。エスケープシーケンスはひとつの要素と解釈されます。もちろんただ単に特殊文字をエスケープするだけでないエスケープシーケンスも存在します。たとえば ``\"\\t\"`` はタブ文字を表します。エスケープシーケンスについては、また後で説明します。ちなみに、この特殊文字についてですが、この入門書の中で何か機能があると紹介する文字はどれも特殊文字であり、したがって文字リテラルとしたいときにはエスケープする必要があると考えてください。" #: ../../../__w/calibre/calibre/manual/regexp.rst:61 msgid "So, what are the most useful sets?" msgstr "一番便利なセットは何ですか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:63 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:" msgstr "聞かれると思ってました。便利なセットといえば、1 桁の数字にマッチする ``[0-9]``、小文字 1 個にマッチする ``[a-z]``、大文字 1 個にマッチする ``[A-Z]``、アルファベット 1 文字にマッチする ``[a-zA-Z]``、そして英数字 1 文字にマッチする ``[a-zA-Z0-9]`` などがあります。略記法としてエスケープシーケンスを使用することもできます:" #: ../../../__w/calibre/calibre/manual/regexp.rst:69 msgid "``\\d``" msgstr "``\\d``" #: ../../../__w/calibre/calibre/manual/regexp.rst:70 msgid "is equivalent to ``[0-9]``" msgstr "``[0-9]`` と同等" #: ../../../__w/calibre/calibre/manual/regexp.rst:72 msgid "``\\w``" msgstr "``\\w``" #: ../../../__w/calibre/calibre/manual/regexp.rst:73 msgid "is equivalent to ``[a-zA-Z0-9_]``" msgstr "``[a-zA-Z0-9_]`` と同等" #: ../../../__w/calibre/calibre/manual/regexp.rst:76 msgid "``\\s``" msgstr "``\\s``" #: ../../../__w/calibre/calibre/manual/regexp.rst:77 msgid "is equivalent to any whitespace" msgstr "空白と同等" #: ../../../__w/calibre/calibre/manual/regexp.rst:80 msgid "" "\"Whitespace\" is a term for anything that won't be printed. These " "characters include space, tabulator, line feed, form feed, carriage return, " "non-breaking spaces, etc." msgstr "\"空白\" とは印刷されないものすべてを表す用語です。空白にはスペース、タブ文字、改行、改ページ、行頭復帰、ノーブレークスペースなどが含まれます。" #: ../../../__w/calibre/calibre/manual/regexp.rst:83 msgid "" "The upper and lower case sets may match both upper and lowercase if the " "setting to make searches case insensitive is enabled. Such settings are " "found, for instance in Preferences->Searching in calibre itself and on the " "Search panel in the calibre :guilabel:`E-book viewer` as well as the calibre" " :guilabel:`Edit book` tool." msgstr "検索で大文字と小文字を区別しない設定が有効になっていると、大文字と小文字のセットは大文字と小文字の両方にマッチします。そのような設定は、たとえば calibre 自身の 環境設定->検索 や calibre :guilabel:`電子書籍ビューア` の検索パネル、そして calibre :guilabel:`本の編集` ツールにあります。" #: ../../../__w/calibre/calibre/manual/regexp.rst:89 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" " ``]*>`` 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." msgstr "セットに関する最後の注意点として、セットはある文字を *除く* すべての文字と定義することが可能です。そのためには、文字 ``\"^\"`` をセットの *一番最初の文字として* 指定します。したがって ``[^a]`` は a 以外のどの文字ともマッチします。これをセットの補完と呼びます。前述したエスケープシーケンスでの略記法にも補完できます。``\"\\D\"`` は数字以外のどの文字にもマッチし、``[^0-9]`` と同等です。その他の略記法も、ご想像のとおり、それぞれ小文字の代わりに大文字を使うと補完になります。では、前の章で例として挙げた ``]*>`` に戻ってみると、ここで使われている文字セットは山カッコを除く文字すべてにマッチさせようとしていることがわかります。" #: ../../../__w/calibre/calibre/manual/regexp.rst:94 msgid "" "But if I had a few varying strings I wanted to match, things get " "complicated?" msgstr "マッチさせたい文字列がいろいろあると、複雑になりますか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:96 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?" msgstr "心配いりません。まだまだ人生は楽勝です。次の例を考えてみましょう: 変換しようとしている本に、奇数ページごとに \"タイトル\" が、偶数ページごとに \"著者名\" が書かれているとします。印刷では見栄えがしますよね? しかし電子書籍では邪魔なだけです。表現全体を普通のカッコで囲むとグループ化できます。そして文字 ``\"|\"`` を使うと右側の表現 *または* 左側の表現の *いずれか* にマッチします。これをつなげれば、おしまいです。速すぎましたか? いいでしょう、まず最初に、奇数ページ用と偶数ページ用に表現をグループ化します。そうすると必要となる 2 つの表現として ``(タイトル)(著者名)`` が得られます。さて、これを縦線 (``\"|\"`` は縦線と呼ばれます) を使って簡単にします。正規表現 ``(タイトル|著者名)`` を使うと、\"タイトル\" (奇数ページ) または \"著者名\" (偶数ページ) のいずれかにマッチするようになります。ほら、簡単でしょう?" #: ../../../__w/calibre/calibre/manual/regexp.rst:98 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." msgstr "もちろん縦線をグループ化するカッコなしで使用することも可能です。ところで量指定子はその前の要素を繰り返すと説明したときのことを覚えていますか? 縦線の作用は少し異なります。正規表現 \"タイトル|著者名\" は、上でグループを使った例とまったく同じように、文字列 \"タイトル\" または文字列 \"著者名\" のいずれかに一致します。*縦線は、その前の表現全部と、その後ろの表現全部のうちから選択します*。したがって、もし文字列 \"Calibre\" と \"calibre\" にマッチさせたくて、大文字と小文字の 違いは\"c\" だけにしたい時は、使用する正規表現は ``(c|C)alibre`` としなくてはなりません。こうすると \"c\" だけが選択されることが保証されます。もし ``c|Calibre`` とすると、文字列 \"c\" または文字列 \"Calibre\" にマッチするため、望んだ結果となりません。要するに、よくわからないときには縦線を使う場合にはグループ化しましょう。" #: ../../../__w/calibre/calibre/manual/regexp.rst:101 msgid "You missed..." msgstr "見落としがあります..." #: ../../../__w/calibre/calibre/manual/regexp.rst:103 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!" msgstr "…ちょっと待ってください。最後にひとつ、グループ化でできるすばらしいことがあります。前にマッチしたグループがあれば、そのグループをその正規表現の中で後で利用できるのです。グループには 1 から始まる番号がつけられ、参照したいグループの番号をエスケープすると参照できます。ですから 5 番目のグループを参照するには ``\\5`` とします。したがって文字列 \"Test Test\" に対して ``([^ ]+) \\1`` で検索すると、文字列全体にマッチします。" #: ../../../__w/calibre/calibre/manual/regexp.rst:107 msgid "" "In the beginning, you said there was a way to make a regular expression case" " insensitive?" msgstr "最初の方で、正規表現に大文字と小文字を区別させない方法があると言いましたよね?" #: ../../../__w/calibre/calibre/manual/regexp.rst:109 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." msgstr "はい、そのとおりです。傾聴とご指摘をありがとうございます。フラグと呼ばれるものを使用すると、calibre にある物事をどのように処理して欲しいのか伝えることができます。フラグを正規表現に含めるには、特殊な構文 ``(?指定フラグ)`` を使用し、「指定フラグ」 の部分を指定したいフラグで置き換えます。大文字と小文字を区別しないようにするフラグは ``i`` なので、正規表現の中に ``(?i)`` を含めます。ですから `(?i)test`` は \"Test\", \"tEst\", \"TEst\" など思いつく限りすべてのバリエーションとマッチします。" #: ../../../__w/calibre/calibre/manual/regexp.rst:111 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." msgstr "もうひとつの便利なフラグ ``s`` を使用すると、ドットを改行を *含めて* すべての文字にマッチさせることができます。正規表現の中で使用したいフラグが複数ある場合には、同じ記述の中に含めてかまいません。``(?is)`` とすると大文字と小文字を区別せず、ドットがすべての文字にマッチします。どちらのフラグを先に記述しても同じです。``(?si)`` は上のものと同等です。" #: ../../../__w/calibre/calibre/manual/regexp.rst:114 msgid "" "I think I'm beginning to understand these regular expressions now... how do " "I use them in calibre?" msgstr "だんだん正規表現がわかってきた気がします。calibre ではどう使いますか?" #: ../../../__w/calibre/calibre/manual/regexp.rst:117 msgid "Conversions" msgstr "変換" #: ../../../__w/calibre/calibre/manual/regexp.rst:119 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::" msgstr "変換の設定から始めましょう。非常によくできています。:guilabel:`検索と置換` の部分に、変換中に置き換えたい文字列を記述する regexp (正規表現の略称) を入力できます。よくできている部分はウィザードです。ウィザードの杖ボタンをクリックすると、変換処理中に calibre に \"見える\" もののプレビューが表示されます。削除したい文字列のところまで下へスクロールして、選択してコピーし、ウィンドウの上部にある正規表現フィールドに貼り付けます。もしページ番号のような可変な部分があればセットと量指定子を使用して保護し、ついでに特殊文字があれば忘れずにエスケープします。:guilabel:`テスト` とラベルのついたボタンを押すと、calibre は正規表現で置換する部分をハイライト表示します。満足できたら OK を押して変換します。もし変換ソースに次の例のようなタグがある場合には、注意してください::" #: ../../../__w/calibre/calibre/manual/regexp.rst:129 msgid "" "(shamelessly ripped out of `this thread " "`_). You'd have " "to remove some of the tags as well. In this example, I'd recommend beginning" " with the tag ````, now you have to end with the " "corresponding closing tag (opening tags are ````, closing tags are " "````), which is simply the next ```` 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 ````, the closing tag using " "````, thus we could remove everything between those tags using " "``.*?``. But using this expression would be a bad idea, because it" " removes everything enclosed by - 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 " "``\\s*Generated\\s+by\\s+ABC\\s+Amber\\s+LIT.*?`` 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." msgstr "(図々しくも `このスレッド `_ からパクってきました) 一部のタグも削除する必要があります。この例では、タグ ```` で開始することをお勧めします。次に、対応する終了タグ (開始タグ ```` で、終了タグは ````) で終了する必要があります。このケースでは単純に次の ```` です。(これに関して不明な点があれば、優れた HTML マニュアルを参照するか、フォーラムで質問してください。) 開始タグは ```` と表すことができ、終了タグは ```` で表せます。したがって ``.*?`` を使用すると、このタグの間にあるものすべてを削除できます。しかしこの正規表現の使用はお勧めできません。なぜなら タグで囲まれたもの (これは囲まれたテキストを太字にします) すべてを削除してしまうため、まず間違いなく本の一部が消えてしまうでしょう。代わりに囲まれた文字列の先頭部分も含めて、正規表現を ``\\s*Generated\\s+by\\s+ABC\\s+Amber\\s+LIT.*?`` とします。見えているとおりにスペースを含める代わりに、どのような文字列の組み合わせになっていてもキャッチできるよう量指定子つきの ``\\s`` が使われています。新しい正規表現をテストするときには、削除したくないものが削除されることのないよう、calibre が何を削除するかを忘れずに確認してください。1 回の出現しか確認しないと、テキストの他の場所での食い違いを見逃す可能性があります。さらに、実際に望んだよりも多いまたは少ないタグを削除してしまうことがありますが、calibre は削除を行った後に破損したコードの修復を試みます。" #: ../../../__w/calibre/calibre/manual/regexp.rst:132 msgid "Adding books" msgstr "本の追加" #: ../../../__w/calibre/calibre/manual/regexp.rst:134 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)`` 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." msgstr "正規表現を使う別の用途は、ファイル名からメタデータを抽出することです。この機能は環境設定の *本の追加* タブにあります。ここには特別な機能があります: メタデータフィールドにフィールド名を使用できるのです。例えば、 ``(?P<title>)`` と指定すると、calibreはこの文字列の部分を本のタイトルとして扱います。使用可能なフィールド名は、便利なテストフィールドと共にウィンドウに表示されます。例えば、 ``Classical Texts: The Divine Comedy by Dante Alighieri.mobi`` といった名前のファイルを大量にインポートするとします。(もちろん、イタリア古典詩が好きな人は皆そうでしょうから、これは既にライブラリに入っています。)あるいは ``Science Fiction epics: The Foundation Trilogy by Isaac Asimov.epub`` といった名前のファイルをインポートするとします。メタデータ抽出の標準表現は ``(?P2.+) - (?P3[^_]+)`` ですので、このままでは明らかに、calibreが意味のあるデータを抽出できません。そのため、ここで有効な正規表現は ``[a-zA-Z]+: (?P<title>.+) by (?P<author>.+)`` となります。メタデータフィールドのグループ内では、フィールドが実際に何に一致するかを表す正規表現を使用する必要があることに注意してください。また、Calibreが提供するテストフィールドを使用する場合は、テストファイル名にファイル拡張子を追加する必要があります。そうしないと、有効な正規表現を使用しても、一致する結果が全く得られません。" #: ../../../__w/calibre/calibre/manual/regexp.rst:138 msgid "Bulk editing metadata" msgstr "書誌を一括編集" #: ../../../__w/calibre/calibre/manual/regexp.rst:140 msgid "" "The last part is regular expression :guilabel:`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! Double-check 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." msgstr "最後の部分は、メタデータフィールドでの正規表現による :guilabel:`検索と置換` です。ライブラリで複数の本を選択し、メタデータの一括編集を使用することで、この機能にアクセスできます。この機能は、ライブラリに **非常に悪い影響** を与える可能性があるため、使用する際は十分に注意してください。テストフィールドを使用して、式が意図したとおりに機能することを再確認し、本当に変更したい本のみにマークを付けてください。正規表現検索モードでは、1つのフィールドで検索し、テキストを何かに置き換え、結果を別のフィールドに書き込むことができます。実用的な例: ライブラリに、Frank Herbert の Dune シリーズの書籍があり、シリーズの流儀で「Dune 1 - Dune」、「Dune 2 - Dune Messiah」などと名付けられているとします。ここで、シリーズフィールドに「Dune」を挿入します。タイトルフィールドで ``(.*?) \\d+ - .*`` を検索し、シリーズフィールドで ``\\1`` に置き換えることで実行できます。何をしたかお分かりですか?これは、シリーズフィールドを置き換える最初のグループへの参照です。これでシリーズの設定がすべて完了したので、タイトルフィールドでもう一度 ``.*? -`` を検索し、 ``\"\"`` (空の文字列)に置き換えるだけで、メタデータがすべて整頓されます。素晴らしいと思いませんか?ちなみに、フィールド全体を置き換える代わりに、フィールドの先頭または末尾に追加することもできます。つまり、本のタイトルの先頭にシリーズ情報を *追加したい* 場合は、それも可能です。もうお気づきだと思いますが、 :guilabel:`大文字と小文字を区別する` というチェックボックスがあるので、ここでフラグを使って動作を選択する必要はありません。" #: ../../../__w/calibre/calibre/manual/regexp.rst:142 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/library/re.html>`_." msgstr "さて、これで正規表現のごく簡単な紹介は終わりです。願わくば紹介した内容が、少なくとも自分で学び続けることができるに足るものでありますように。 `Python documentation for regexps <https://docs.python.org/library/re.html>`_ から始めるとよいでしょう。" #: ../../../__w/calibre/calibre/manual/regexp.rst:144 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." msgstr "ただし最後にひとつだけ警告しておきます。正規表現は強力ですが、同時にまた非常に簡単に間違いを引き起こすものでもあります。calibre は正規表現が期待どおりに動くかどうか確認するために、すばらしいテストツールを用意しています。それを利用してください。自分の足を撃ち抜くような真似はしないでください。(この表現、素敵でしょう…) けれどももし、警告があったにもかかわらず足 (または身体のどこか他の部分) にケガを負ってしまった場合には、そこから学ぶよう努めてください。" #: ../../../__w/calibre/calibre/manual/regexp.rst:148 msgid "Quick reference" msgstr "クイックリファレンス" #: ../../../__w/calibre/calibre/manual/regexp.rst:156 msgid "Credits" msgstr "謝辞" #: ../../../__w/calibre/calibre/manual/regexp.rst:158 msgid "Thanks for helping with tips, corrections and such:" msgstr "記述や誤字修正などの助力に感謝します。" #: ../../../__w/calibre/calibre/manual/regexp.rst:160 msgid "ldolse" msgstr "ldolse" #: ../../../__w/calibre/calibre/manual/regexp.rst:161 msgid "kovidgoyal" msgstr "kovidgoyal" #: ../../../__w/calibre/calibre/manual/regexp.rst:162 msgid "chaley" msgstr "chaley" #: ../../../__w/calibre/calibre/manual/regexp.rst:163 msgid "dwanthny" msgstr "dwanthny" #: ../../../__w/calibre/calibre/manual/regexp.rst:164 msgid "kacir" msgstr "kacir" #: ../../../__w/calibre/calibre/manual/regexp.rst:165 msgid "Starson17" msgstr "Starson17" #: ../../../__w/calibre/calibre/manual/regexp.rst:166 msgid "Orpheu" msgstr "Orpheu" #: ../../../__w/calibre/calibre/manual/regexp.rst:168 msgid "" "For more about regexps see `The Python User Manual " "<https://docs.python.org/library/re.html>`_. The actual regular expression " "library used by calibre is: `regex <https://bitbucket.org/mrabarnett/mrab-" "regex/src/hg/>`_ which supports several useful enhancements over the Python " "standard library one." msgstr "正規表現についてさらに詳しく学ぶには、 `The Python User Manual <https://docs.python.org/library/re.html>`_ を参照してください。calibre で使用している正規表現ライブラリは `regex <https://bitbucket.org/mrabarnett/mrab-regex/src/hg/>`_ です。これは Python 標準のライブラリに比較するといくつか便利な拡張機能を備えています。"