- From: Manger, James H <James.H.Manger@team.telstra.com>
- Date: Fri, 26 Oct 2007 15:46:47 +1000
- 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 UTC