Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Request Subsets of Configuration Objects Using Regular Expressions

In a Junos XML protocol session with a device running Junos OS, to request information about only those instances of a configuration object type that have a specified set of characters in their identifier names, a client application includes the matching attribute with a regular expression that matches the identifier name. For example, the application can request information about just the SONET/SDH interfaces at the [edit interfaces] hierarchy level by specifying the characters so- at the start of the regular expression.

Using the matching attribute enables the application to represent the objects to return in a form similar to the XML Path Language (XPath) representation, which is described in XML Path Language (XPath) Version 1.0, available from the World Wide Web Consortium (W3C) at http://www.w3.org/TR/xpath . In an XPath representation, an object and its parent levels are an ordered series of tag element names separated by forward slashes. The angle brackets around tag element names are omitted, and the opening tag is used to represent the entire tag element. For example, the following XPath:

is equivalent to the following tagged representation:

The application includes the matching attribute in the empty tag that represents a parent level for the object type. As with all requests for configuration information, the client emits a <get-configuration> tag element that encloses the tag elements representing all levels of the configuration hierarchy from the root (represented by the <configuration> tag element) down to the level at which the matching attribute is included. The entire request is enclosed in an <rpc> tag element:

In the value for the matching attribute, each level in the XPath-like representation can be either a full level name or a regular expression that matches the identifier name of one or more instances of an object type:

The regular expression uses the notation defined in POSIX Standard 1003.2 for extended (modern) UNIX regular expressions. Explaining regular expression syntax is beyond the scope of this document, but Table 1 specifies which character or characters are matched by some of the regular expression operators that can be used in the expression. In the descriptions, the term term refers to either a single alphanumeric character or a set of characters enclosed in square brackets, parentheses, or braces.

Note:

The matching attribute is not case-sensitive.

 

Table 1: Regular Expression Operators for the matching Attribute

Operator

Matches

. (period)

One instance of any character except the space.

* (asterisk)

Zero or more instances of the immediately preceding term.

+ (plus sign)

One or more instances of the immediately preceding term.

? (question mark)

Zero or one instance of the immediately preceding term.

| (pipe) 

One of the terms that appear on either side of the pipe operator.

^ (caret) 

The start of a line, when the caret appears outside square brackets.

One instance of any character that does not follow it within square brackets, when the caret is the first character inside square brackets.

$ (dollar sign) 

The end of a line.

[ ] (paired square brackets)

One instance of one of the enclosed alphanumeric characters. To indicate a range of characters, use a hyphen (-) to separate the beginning and ending characters of the range. For example, [a-z0-9] matches any letter or number.

( ) (paired parentheses) 

One instance of the evaluated value of the enclosed term. Parentheses are used to indicate the order of evaluation in the regular expression.

When the application requests Junos XML-tagged output (the default), the Junos XML protocol server returns the requested object in <configuration> and <rpc-reply> tag elements. For information about the attributes in the opening <configuration> tag, see Specifying the Source for Configuration Information Requests in a Junos XML Protocol Session.

The application can combine one or more of the count, start, and recurse attributes along with the matching attribute, to limit the set of possible matches to a specific range of objects, to request only identifiers, or both. For more information about those attributes, see Requesting a Specific Number of Configuration Objects Using the Junos XML Protocol and Requesting Identifiers for Configuration Objects of a Specific Type Using the Junos XML Protocol.

To specify the source of the output (candidate or active configuration) and request special formatting of the output (for example, formatted ASCII or JSON or an indicator for identifiers), the application can include attributes in the opening <get-configuration> tag, its opening <junoscript> tag, or both. For more information, see Specifying the Source for Configuration Information Requests in a Junos XML Protocol Session and Specifying the Output Format for Configuration Data in a Junos XML Protocol Session.

The application can request additional configuration elements of the same or other types in the same <get-configuration> tag element by including the appropriate tag elements. For more information, see Requesting Multiple Configuration Elements Using the Junos XML Protocol.

The following example shows how to request just the identifier for the first two SONET/SDH interfaces configured at the [edit interfaces] hierarchy level.