Project

General

Profile

Actions

Regex » History » Revision 2

« Previous | Revision 2/7 (diff) | Next »
Yingdi Yu, 03/19/2014 11:19 AM


NDN Regular Expression

NDN regular expression matching is done at two levels: one at the name level and one at the name component level.

We use < and > to enclose a name component matcher which specifies the pattern of a name component.
The component pattern is expressed using the Perl Regular Expression Syntax.
For example, <ab*c> can match the 1st, 3rd, and 4th components of "/ac/dc/abc/abbc", but it cannot match the 2nd component.
A special case is that <> is a wildcard matcher that can match ANY component.

Note that a component match can match only one name component.
In order to match a name, you need to specify the pattern of a name based on the name component matchers.
For example, <ndn><edu><ucla> can match the name "/ndn/edu/ucla".
In order to describe a more complicated name pattern, we borrow some syntaxes from the standard regular expressions.

NDN Regex Syntax

Anchors

A '' character shall match the start of a name.
For example, ^<ndn> shall match any names starting with a component "ndn", and it will exclude a name like "/local/broadcast".

A '$' character shall match the end of a name.
For example, ^<ndn><edu>$ shall match only one name: "/ndn/edu".

A NDN regular expression is built on the component matcher extended from the standard regex by simply treating a component matcher as a single character in standard regex.
For example,
^<ndn> can match any names starting with a component "ndn";
<test>$ can match any names ending with a component "test";
^[^<ndn>] can match any names that do not start with a component "ndn";
^([^<DNS>])<DNS>(<>*)<NS> can match a NDN DNS data name, and you can use back reference to extract the part enclosed by ( and )
("\1\2" can extract /ndn/edu/ucla/irl from /ndn/edu/ucla/DNS/irl/NS/123456.

Updated by Yingdi Yu about 10 years ago · 2 revisions