<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><section><h1>Appendix B.  Parsing a URI Reference with a Regular Expression</h1><blockquote><p>As the &quot;first-match-wins&quot; algorithm is identical to the &quot;greedy&quot;
disambiguation method used by POSIX regular expressions, it is
natural and commonplace to use a regular expression for parsing the
potential five components of a URI reference.</p></blockquote><p><q>早い者勝ち</q>法は POSIX 正規表現で使われている曖昧さをなくすための<q>貪欲</q>法と同じものですから、
URI 参照の5つの部品を構文解析するのに正規表現を使うのは自然なことです。</p><blockquote><p>The following line is the regular expression for breaking-down a
well-formed URI reference into its components.</p></blockquote><p>次に示すのは整形式 URI 参照を部品に分割するための正規表現です。</p><blockquote><pre>      ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
       12            3  4          5       6  7        8 9</pre></blockquote><blockquote><p>The numbers in the second line above are only to assist readability;
they indicate the reference points for each subexpression (i.e., each
paired parenthesis).  We refer to the value matched for subexpression
&lt;n&gt; as $&lt;n&gt;.  For example, matching the above expression to</p></blockquote><p>2行目の番号は可読性のために付記しただけのものです。
この数字は各部分式の参照点 (組になった括弧) を示しています。
部分式 <var>n</var> に一致した値を <code>$<var>n</var></code> と書くことにします。
例として、先の正規表現は</p><blockquote><p><samp class="URI">http://www.ics.uci.edu/pub/ietf/uri/#Related</samp></p></blockquote><blockquote><p>results in the following subexpression matches:</p></blockquote><p>と一致し、部分式は次のように一致します。</p><blockquote><pre>      $1 = http:
      $2 = http
      $3 = //www.ics.uci.edu
      $4 = www.ics.uci.edu
      $5 = /pub/ietf/uri/
      $6 = &lt;undefined&gt;
      $7 = &lt;undefined&gt;
      $8 = #Related
      $9 = Related</pre></blockquote><blockquote><p>where &lt;undefined&gt; indicates that the component is not present, as is
the case for the query component in the above example.  Therefore, we
can determine the value of the five components as</p></blockquote><p>ここで、 <code>&lt;undefined&gt;</code> はこの例での <code class="ABNF">query</code>
部品のように、部品が現れなかったことを示します。従って、
5つの部品の値は次のように決めることができます。</p><blockquote><pre>      scheme    = $2
      authority = $4
      path      = $5
      query     = $7
      fragment  = $9</pre></blockquote><blockquote><p>Going in the opposite direction, we can recreate a URI reference from
its components by using the algorithm of Section 5.3.</p></blockquote><p>逆方向に進めることで5.3節の方法を使って部品から URI
参照を再生成することもできます。</p></section><section><h1>License</h1><p><anchor xmlns="urn:x-suika-fam-cx:markup:suikawiki:0:9:">RFCのライセンス</anchor></p></section><section><h1>メモ</h1></section></body></html>