@@ -2006,6 +2006,9 @@ msgid ""
20062006" ``word`` have a word boundary on either side. This takes the job beyond "
20072007":meth:`!replace`'s abilities.)"
20082008msgstr ""
2009+ "一つの例としては、単一の固定文字列を別の固定文字列に置き換える作業があるでしょう; 例えば ``word`` を ``deed`` で置換したい場合です。\n"
2010+ ":func:`re.sub` はこの目的で使う関数のように思えますが、 :meth:`~str.replace` メソッドを利用することを考えた方がいいでしょう。\n"
2011+ ":meth:`!replace` は単語内の ``word`` も置換し、 ``swordfish`` を ``sdeedfish`` に変えますが、安直な正規表現 ``word`` も同様に動作することに注意して下さい。(単語の一部に対する置換の実行を避けるには、パターンを ``\\bword\\b`` として、 ``word`` の両側に単語の境界が要求されるようにします。これは :meth:`!replace` の能力を越えた作業です。)"
20092012
20102013#: ../../howto/regex.rst:1252
20112014msgid ""
@@ -2015,6 +2018,9 @@ msgid ""
20152018" capable of doing both tasks and will be faster than any regular expression "
20162019"operation can be."
20172020msgstr ""
2021+ "別のよくある作業は、文字列の中に出現する文字を全て削除することと、別の文字で置換することです。この作業を ``re.sub('\\n', ' ', "
2022+ "S)`` のようにして行うかもしれませんが、 :meth:`~str.translate` "
2023+ "は削除と置換の両方の作業をこなし、正規表現操作よりも高速に行うことができます。"
20182024
20192025#: ../../howto/regex.rst:1258
20202026msgid ""
@@ -2035,12 +2041,15 @@ msgid ""
20352041"start at 0; if the match wouldn't start at zero, :func:`!match` will *not* "
20362042"report it. ::"
20372043msgstr ""
2044+ ":func:`~re.match` 関数は文字列の先頭に正規表現がマッチするかどうか調べるだけですが、その一方 :func:`~re.search` はマッチするために文字列の先の方まで走査します。\n"
2045+ "この違いを覚えておくことは重要なことです。\n"
2046+ ":func:`!match` は開始位置0でマッチが成功したときのみ報告する; もし開始位置0でマッチしなければ、 :func:`!match` はそれを報告 *しない* 、ということを覚えておいてください。 ::"
20382047
20392048#: ../../howto/regex.rst:1276
20402049msgid ""
20412050"On the other hand, :func:`~re.search` will scan forward through the string, "
20422051"reporting the first match it finds. ::"
2043- msgstr ""
2052+ msgstr "一方 :func:`~re.search` は文字列の先の方まで走査し、最初にみつけたマッチを報告します。:: "
20442053
20452054#: ../../howto/regex.rst:1284
20462055msgid ""
@@ -2097,6 +2106,9 @@ msgid ""
20972106"The final match extends from the ``'<'`` in ``'<html>'`` to the ``'>'`` in "
20982107"``'</title>'``, which isn't what you want."
20992108msgstr ""
2109+ "正規表現は ``'<html>'`` 内の ``'<'`` にマッチし、 ``.*`` は残りの文字列の全てにマッチします。\n"
2110+ "しかし、正規表現には依然として残っている部分があって、 ``>`` は文字列の終端にマッチしないので、正規表現エンジンは一文字ずつ ``>`` とマッチするまで引き返すことになります。\n"
2111+ "最終的にマッチする領域は ``'<html>'`` の ``'<'`` から ``'</title>'`` の ``'>'`` まで広がりますが、これは望んだ結果ではありません。"
21002112
21012113#: ../../howto/regex.rst:1322
21022114msgid ""
@@ -2143,6 +2155,8 @@ msgid ""
21432155"regular expression can be helpful, because it allows you to format the "
21442156"regular expression more clearly."
21452157msgstr ""
2158+ "そのような正規表現に対しては、正規表現をコンパイルする時に :const:`re.VERBOSE` "
2159+ "フラグを指定することが助けになります。なぜなら、より明確な書式で正規表現を書けるからです。"
21462160
21472161#: ../../howto/regex.rst:1350
21482162msgid ""
@@ -2186,3 +2200,8 @@ msgid ""
21862200"edition covered Python's now-removed :mod:`!regex` module, which won't help "
21872201"you much.) Consider checking it out from your library."
21882202msgstr ""
2203+ "O'Reilly から出版されている Jeffrey Friedl の Mastering Regular Expressions "
2204+ "は正規表現に関するほぼ完璧な書籍です (訳注 日本語訳「詳説 正規表現」が出版されています) 。不幸なことに、この本は Perl と Java "
2205+ "の正規表現を集中して扱っていて、 Python の正規表現については全く扱っていません、そのため Python "
2206+ "プログラミングのためのレファレンスとして使うことはできません。 (第一版はいまや削除された Python の :mod:`!regex` "
2207+ "モジュールについて扱っていましたが、これはあまり役に立たないでしょう。) 図書館で調べるのを検討してみましょう。"
0 commit comments