W3C home > Mailing lists > Public > uri@w3.org > October 2007

RE: URI Templates: { ^ prefix ^ variable [] separator | default }

From: Manger, James H <James.H.Manger@team.telstra.com>
Date: Fri, 26 Oct 2007 15:46:47 +1000
Message-ID: <6215401E01247448A306C54F499111F20362A99D@WSMSG2103V.srv.dir.telstra.com>
To: <uri@w3.org>
This syntax can be parsed with a single regular expression:

\{(\^)?(?:([^\^]*?)\^?)(|[a-zA-Z][a-zA-Z\._~-]*+)(?:\[\]([^\|\}]*+))?(?:\|([^\}]*))?\}

Groups 1-5 correspond to ^ (encoding), <prefix>, <variable>, <separator> and <default> respectively.

Or in Java (which extra \’s to escape \’s):

        public static final Pattern REGEX = Pattern.compile(
            "\\{" +                             //   {
                "(\\^)?" +                      // 1  ^
                "(?:([^\\^]*?)\\^?)" +          // 2  prefix ^
                "(|[a-zA-Z][a-zA-Z\\._~-]*+)" + // 3  variable
                "(?:\\[\\]([^\\|\\}]*+))?" +    // 4  [] separator
                "(?:\\|([^\\}]*))?" +           // 5  | default
            "\\}");                             //   }

Substituting { ^ prefix ^ variable [] separator | default } gives:
1. if variable is undefined: <default> (or an empty string)
2. if variable is a single value: <prefix><variable>
3. if variable is a list: <prefix><variable[0]><separator><variable[1]>…

Received on Friday, 26 October 2007 05:53:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 13 January 2011 12:15:37 GMT