PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/library/re.rst.diff.html

https://code.google.com/p/python-doc-ja/
HTML | 282 lines | 236 code | 46 blank | 0 comment | 0 complexity | 9193bedaae1987af7696b941acda3e72 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <title>library/re.rst</title>
  5. <style type="text/css">
  6. .highlight .hll { background-color: #ffffcc }
  7. .highlight { background: #f8f8f8; }
  8. .highlight .c { color: #408080; font-style: italic } /* Comment */
  9. .highlight .err { border: 1px solid #FF0000 } /* Error */
  10. .highlight .k { color: #008000; font-weight: bold } /* Keyword */
  11. .highlight .o { color: #666666 } /* Operator */
  12. .highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
  13. .highlight .cp { color: #BC7A00 } /* Comment.Preproc */
  14. .highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
  15. .highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
  16. .highlight .gd { color: #A00000 } /* Generic.Deleted */
  17. .highlight .ge { font-style: italic } /* Generic.Emph */
  18. .highlight .gr { color: #FF0000 } /* Generic.Error */
  19. .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
  20. .highlight .gi { color: #00A000 } /* Generic.Inserted */
  21. .highlight .go { color: #808080 } /* Generic.Output */
  22. .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
  23. .highlight .gs { font-weight: bold } /* Generic.Strong */
  24. .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
  25. .highlight .gt { color: #0040D0 } /* Generic.Traceback */
  26. .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
  27. .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
  28. .highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
  29. .highlight .kp { color: #008000 } /* Keyword.Pseudo */
  30. .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
  31. .highlight .kt { color: #B00040 } /* Keyword.Type */
  32. .highlight .m { color: #666666 } /* Literal.Number */
  33. .highlight .s { color: #BA2121 } /* Literal.String */
  34. .highlight .na { color: #7D9029 } /* Name.Attribute */
  35. .highlight .nb { color: #008000 } /* Name.Builtin */
  36. .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
  37. .highlight .no { color: #880000 } /* Name.Constant */
  38. .highlight .nd { color: #AA22FF } /* Name.Decorator */
  39. .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
  40. .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
  41. .highlight .nf { color: #0000FF } /* Name.Function */
  42. .highlight .nl { color: #A0A000 } /* Name.Label */
  43. .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
  44. .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
  45. .highlight .nv { color: #19177C } /* Name.Variable */
  46. .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
  47. .highlight .w { color: #bbbbbb } /* Text.Whitespace */
  48. .highlight .mf { color: #666666 } /* Literal.Number.Float */
  49. .highlight .mh { color: #666666 } /* Literal.Number.Hex */
  50. .highlight .mi { color: #666666 } /* Literal.Number.Integer */
  51. .highlight .mo { color: #666666 } /* Literal.Number.Oct */
  52. .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
  53. .highlight .sc { color: #BA2121 } /* Literal.String.Char */
  54. .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
  55. .highlight .s2 { color: #BA2121 } /* Literal.String.Double */
  56. .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
  57. .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
  58. .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
  59. .highlight .sx { color: #008000 } /* Literal.String.Other */
  60. .highlight .sr { color: #BB6688 } /* Literal.String.Regex */
  61. .highlight .s1 { color: #BA2121 } /* Literal.String.Single */
  62. .highlight .ss { color: #19177C } /* Literal.String.Symbol */
  63. .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
  64. .highlight .vc { color: #19177C } /* Name.Variable.Class */
  65. .highlight .vg { color: #19177C } /* Name.Variable.Global */
  66. .highlight .vi { color: #19177C } /* Name.Variable.Instance */
  67. .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
  68. </style>
  69. </head>
  70. <body>
  71. <div class="highlight"><pre><span class="gu">@@ -215,25 +215,25 @@</span>
  72. and :const:`re.X` (verbose), for the entire regular expression. (The
  73. flags are described in :ref:`contents-of-module-re`.) This
  74. is useful if you wish to include the flags as part of the regular
  75. expression, instead of passing a *flag* argument to the
  76. :func:`re.compile` function.
  77. Note that the ``(?x)`` flag changes how the expression is parsed. It should be
  78. used first in the expression string, or after one or more whitespace characters.
  79. If there are non-whitespace characters before the flag, the results are
  80. undefined.
  81. ``(?:...)``
  82. <span class="gd">- A non-grouping version of regular parentheses. Matches whatever regular</span>
  83. <span class="gi">+ A non-capturing version of regular parentheses. Matches whatever regular</span>
  84. expression is inside the parentheses, but the substring matched by the group
  85. *cannot* be retrieved after performing a match or referenced later in the
  86. pattern.
  87. ``(?P&lt;name&gt;...)``
  88. Similar to regular parentheses, but the substring matched by the group is
  89. accessible within the rest of the regular expression via the symbolic group
  90. name *name*. Group names must be valid Python identifiers, and each group
  91. name must be defined only once within a regular expression. A symbolic group
  92. is also a numbered group, just as if the group were not named. So the group
  93. named ``id`` in the example below can also be referenced as the numbered group
  94. ``1``.
  95. <span class="gu">@@ -323,25 +323,26 @@</span>
  96. precise set of characters deemed to be alphanumeric depends on the values of the
  97. ``UNICODE`` and ``LOCALE`` flags. Inside a character range, ``\b`` represents
  98. the backspace character, for compatibility with Python&#39;s string literals.
  99. ``\B``
  100. Matches the empty string, but only when it is *not* at the beginning or end of a
  101. word. This is just the opposite of ``\b``, so is also subject to the settings
  102. of ``LOCALE`` and ``UNICODE``.
  103. ``\d``
  104. When the :const:`UNICODE` flag is not specified, matches any decimal digit; this
  105. is equivalent to the set ``[0-9]``. With :const:`UNICODE`, it will match
  106. <span class="gd">- whatever is classified as a digit in the Unicode character properties database.</span>
  107. <span class="gi">+ whatever is classified as a decimal digit in the Unicode character properties</span>
  108. <span class="gi">+ database.</span>
  109. ``\D``
  110. When the :const:`UNICODE` flag is not specified, matches any non-digit
  111. character; this is equivalent to the set ``[^0-9]``. With :const:`UNICODE`, it
  112. will match anything other than character marked as digits in the Unicode
  113. character properties database.
  114. ``\s``
  115. When the :const:`LOCALE` and :const:`UNICODE` flags are not specified, matches
  116. any whitespace character; this is equivalent to the set ``[ \t\n\r\f\v]``. With
  117. :const:`LOCALE`, it will match this set plus whatever characters are defined as
  118. space for the current locale. If :const:`UNICODE` is set, this will match the
  119. <span class="gu">@@ -527,59 +528,64 @@</span>
  120. If zero or more characters at the beginning of *string* match the regular
  121. expression *pattern*, return a corresponding :class:`MatchObject` instance.
  122. Return ``None`` if the string does not match the pattern; note that this is
  123. different from a zero-length match.
  124. .. note::
  125. If you want to locate a match anywhere in *string*, use :func:`search`
  126. instead.
  127. <span class="gd">-.. function:: split(pattern, string[, maxsplit=0])</span>
  128. <span class="gi">+.. function:: split(pattern, string[, maxsplit=0, flags=0])</span>
  129. Split *string* by the occurrences of *pattern*. If capturing parentheses are
  130. used in *pattern*, then the text of all groups in the pattern are also returned
  131. as part of the resulting list. If *maxsplit* is nonzero, at most *maxsplit*
  132. splits occur, and the remainder of the string is returned as the final element
  133. of the list. (Incompatibility note: in the original Python 1.5 release,
  134. *maxsplit* was ignored. This has been fixed in later releases.)
  135. &gt;&gt;&gt; re.split(&#39;\W+&#39;, &#39;Words, words, words.&#39;)
  136. [&#39;Words&#39;, &#39;words&#39;, &#39;words&#39;, &#39;&#39;]
  137. &gt;&gt;&gt; re.split(&#39;(\W+)&#39;, &#39;Words, words, words.&#39;)
  138. [&#39;Words&#39;, &#39;, &#39;, &#39;words&#39;, &#39;, &#39;, &#39;words&#39;, &#39;.&#39;, &#39;&#39;]
  139. &gt;&gt;&gt; re.split(&#39;\W+&#39;, &#39;Words, words, words.&#39;, 1)
  140. [&#39;Words&#39;, &#39;words, words.&#39;]
  141. <span class="gi">+ &gt;&gt;&gt; re.split(&#39;[a-f]+&#39;, &#39;0a3B9&#39;, flags=re.IGNORECASE)</span>
  142. <span class="gi">+ [&#39;0&#39;, &#39;3&#39;, &#39;9&#39;]</span>
  143. If there are capturing groups in the separator and it matches at the start of
  144. the string, the result will start with an empty string. The same holds for
  145. the end of the string:
  146. &gt;&gt;&gt; re.split(&#39;(\W+)&#39;, &#39;...words, words...&#39;)
  147. [&#39;&#39;, &#39;...&#39;, &#39;words&#39;, &#39;, &#39;, &#39;words&#39;, &#39;...&#39;, &#39;&#39;]
  148. That way, separator components are always found at the same relative
  149. indices within the result list (e.g., if there&#39;s one capturing group
  150. in the separator, the 0th, the 2nd and so forth).
  151. Note that *split* will never split a string on an empty pattern match.
  152. For example:
  153. &gt;&gt;&gt; re.split(&#39;x*&#39;, &#39;foo&#39;)
  154. [&#39;foo&#39;]
  155. &gt;&gt;&gt; re.split(&quot;(?m)^$&quot;, &quot;foo\n\nbar\n&quot;)
  156. [&#39;foo\n\nbar\n&#39;]
  157. <span class="gi">+ .. versionchanged:: 2.7</span>
  158. <span class="gi">+ Added the optional flags argument.</span>
  159. <span class="gi">+</span>
  160. .. function:: findall(pattern, string[, flags])
  161. Return all non-overlapping matches of *pattern* in *string*, as a list of
  162. strings. The *string* is scanned left-to-right, and matches are returned in
  163. the order found. If one or more groups are present in the pattern, return a
  164. list of groups; this will be a list of tuples if the pattern has more than
  165. one group. Empty matches are included in the result unless they touch the
  166. beginning of another match.
  167. .. versionadded:: 1.5.2
  168. <span class="gu">@@ -592,75 +598,81 @@</span>
  169. Return an :term:`iterator` yielding :class:`MatchObject` instances over all
  170. non-overlapping matches for the RE *pattern* in *string*. The *string* is
  171. scanned left-to-right, and matches are returned in the order found. Empty
  172. matches are included in the result unless they touch the beginning of another
  173. match.
  174. .. versionadded:: 2.2
  175. .. versionchanged:: 2.4
  176. Added the optional flags argument.
  177. <span class="gd">-.. function:: sub(pattern, repl, string[, count])</span>
  178. <span class="gi">+.. function:: sub(pattern, repl, string[, count, flags])</span>
  179. Return the string obtained by replacing the leftmost non-overlapping occurrences
  180. of *pattern* in *string* by the replacement *repl*. If the pattern isn&#39;t found,
  181. *string* is returned unchanged. *repl* can be a string or a function; if it is
  182. a string, any backslash escapes in it are processed. That is, ``\n`` is
  183. converted to a single newline character, ``\r`` is converted to a linefeed, and
  184. so forth. Unknown escapes such as ``\j`` are left alone. Backreferences, such
  185. as ``\6``, are replaced with the substring matched by group 6 in the pattern.
  186. For example:
  187. &gt;&gt;&gt; re.sub(r&#39;def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):&#39;,
  188. ... r&#39;static PyObject*\npy_\1(void)\n{&#39;,
  189. ... &#39;def myfunc():&#39;)
  190. &#39;static PyObject*\npy_myfunc(void)\n{&#39;
  191. If *repl* is a function, it is called for every non-overlapping occurrence of
  192. *pattern*. The function takes a single match object argument, and returns the
  193. replacement string. For example:
  194. &gt;&gt;&gt; def dashrepl(matchobj):
  195. ... if matchobj.group(0) == &#39;-&#39;: return &#39; &#39;
  196. ... else: return &#39;-&#39;
  197. &gt;&gt;&gt; re.sub(&#39;-{1,2}&#39;, dashrepl, &#39;pro----gram-files&#39;)
  198. &#39;pro--gram files&#39;
  199. <span class="gi">+ &gt;&gt;&gt; re.sub(r&#39;\sAND\s&#39;, &#39; &amp; &#39;, &#39;Baked Beans And Spam&#39;, flags=re.IGNORECASE)</span>
  200. <span class="gi">+ &#39;Baked Beans &amp; Spam&#39;</span>
  201. <span class="gd">- The pattern may be a string or an RE object; if you need to specify regular</span>
  202. <span class="gd">- expression flags, you must use a RE object, or use embedded modifiers in a</span>
  203. <span class="gd">- pattern; for example, ``sub(&quot;(?i)b+&quot;, &quot;x&quot;, &quot;bbbb BBBB&quot;)`` returns ``&#39;x x&#39;``.</span>
  204. <span class="gi">+ The pattern may be a string or an RE object.</span>
  205. The optional argument *count* is the maximum number of pattern occurrences to be
  206. replaced; *count* must be a non-negative integer. If omitted or zero, all
  207. occurrences will be replaced. Empty matches for the pattern are replaced only
  208. when not adjacent to a previous match, so ``sub(&#39;x*&#39;, &#39;-&#39;, &#39;abc&#39;)`` returns
  209. ``&#39;-a-b-c-&#39;``.
  210. In addition to character escapes and backreferences as described above,
  211. ``\g&lt;name&gt;`` will use the substring matched by the group named ``name``, as
  212. defined by the ``(?P&lt;name&gt;...)`` syntax. ``\g&lt;number&gt;`` uses the corresponding
  213. group number; ``\g&lt;2&gt;`` is therefore equivalent to ``\2``, but isn&#39;t ambiguous
  214. in a replacement such as ``\g&lt;2&gt;0``. ``\20`` would be interpreted as a
  215. reference to group 20, not a reference to group 2 followed by the literal
  216. character ``&#39;0&#39;``. The backreference ``\g&lt;0&gt;`` substitutes in the entire
  217. substring matched by the RE.
  218. <span class="gi">+ .. versionchanged:: 2.7</span>
  219. <span class="gi">+ Added the optional flags argument.</span>
  220. <span class="gd">-.. function:: subn(pattern, repl, string[, count])</span>
  221. <span class="gi">+</span>
  222. <span class="gi">+.. function:: subn(pattern, repl, string[, count, flags])</span>
  223. Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
  224. number_of_subs_made)``.
  225. <span class="gi">+ .. versionchanged:: 2.7</span>
  226. <span class="gi">+ Added the optional flags argument.</span>
  227. <span class="gi">+</span>
  228. .. function:: escape(string)
  229. Return *string* with all non-alphanumerics backslashed; this is useful if you
  230. want to match an arbitrary literal string that may have regular expression
  231. metacharacters in it.
  232. .. function:: purge()
  233. Clear the regular expression cache.
  234. </pre></div>
  235. </body>
  236. </html>