URI共通構文(B)

広告

広告

原文

最終更新
2006-04-14T01:01:00+09:00
この記事のURI参照
https://www.7key.jp/rfc/2396/rfc2396_b.html#source

URI共通構文(和訳)

最終更新
2006-09-27T00:00:00+09:00
この記事のURI参照
https://www.7key.jp/rfc/2396/rfc2396_b.html#translation

B. Parsing a URI Reference with a Regular Expression

   As described in Section 4.3, the generic URI syntax is not sufficient
   to disambiguate the components of some forms of URI.  Since the
   "greedy algorithm" described in that section is identical to the
   disambiguation method used by POSIX regular expressions, it is
   natural and commonplace to use a regular expression for parsing the
   potential four components and fragment identifier of a URI reference.

4.3. URI参照の構文解析で触れたが、共通URI構文はURIの書式によってはそのコンポーネントを明確にする上で十分とは言えないものである。その章で触れた"より厳密なアルゴリズム"は、POSIX正規表現で用いられる明確化手法と同一であるため、URI参照に含まれる可能性のある4つのコンポーネントとフラグメント識別子を解析する際に正規表現を用いることは自然であり当然のことである。

   The following line is the regular expression for breaking-down a URI
   reference into its components.

      ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
       12            3  4          5       6  7        8 9

これは、URI参照を各コンポーネントに分解するための正規表現である。

   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
   <n> as $<n>.  For example, matching the above expression to

      http://www.ics.uci.edu/pub/ietf/uri/#Related

   results in the following subexpression matches:

上記番号は可読性のためだけに振られており、各部分表現(つまり、各括弧の組)の参照個所を示している。各部分表現<n>にマッチする値をそれぞれ$<n>で示す。例えばhttp://www.ics.uci.edu/pub/ietf/uri/#Relatedにマッチさせた結果は次の通りである。

      $1 = http:
      $2 = http
      $3 = //www.ics.uci.edu
      $4 = www.ics.uci.edu
      $5 = /pub/ietf/uri/
      $6 = <undefined>
      $7 = <undefined>
      $8 = #Related
      $9 = Related
   where <undefined> 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 four components and fragment as

      scheme    = $2
      authority = $4
      path      = $5
      query     = $7
      fragment  = $9

   and, going in the opposite direction, we can recreate a URI reference
   from its components using the algorithm in step 7 of Section 5.2. 

ここで、<undefined>はコンポーネントがないことを示し、上記の例ではクエリコンポーネントがこれにあたる。従って、4つのコンポーネントとフラグメント識別子はこのように確定でき、逆に辿れば「5.2. 相対参照を絶対形式へ解決する方法」のステップ7のアルゴリズムを用いてコンポーネントからURI参照を再構築することができる。

広告

Copyright (C) 2006 七鍵 key@do.ai 初版:2006年04月14日 最終更新:2006年09月27日