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

A Junos XML protocol client application can request information for configuration object instances that include a specified set of characters in their identifiers. To filter the objects by identifier, a client application includes the matching attribute with a regular expression that matches on the identifiers. For example, the application can specify a regular expression that matches on the characters "ge-" to request information about the Gigabit Ethernet interfaces at the [edit interfaces] hierarchy level.

The matching attribute enables the application to represent the objects to return in a form similar to the XML Path Language (XPath) representation. For example, the following XPath:

is equivalent to the following tagged representation:

For more information about XPath, see XML Path Language (XPath) Version 1.0.

To filter by identifier, 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 matching attribute is case-insensitive. 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. For example:

The regular expression uses the notation defined in POSIX Standard 1003.2 for extended (modern) UNIX regular expressions. Table 1 specifies which character or characters are matched by some of the regular expression operators that you can use 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.

Table 1: Regular Expression Operators for the matching Attribute

Operator

Matches

. (period)

One instance of any character.

* (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 <rpc-reply> and <configuration> elements.

The application can combine one or more of the count, start, and recurse attributes along with the matching attribute. These attributes enable you to limit the set of possible matches to a specific range of objects, to request only identifiers, or both. For more information about these attributes, see:

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:

The same <get-configuration> operation can also request additional configuration elements of the same or other types in 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 Gigabit Ethernet interfaces configured at the [edit interfaces] hierarchy level:

The Junos XML protocol server returns the identifiers for the requested objects.