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:
configuration/system/radius-server/name
is equivalent to the following tagged representation:
<configuration>
<system>
<radius-server>
<name/>
</radius-server>
</system>
</configuration>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.
<rpc>
<get-configuration>
<configuration>
<!-- opening tags for each parent of the level -->
<level matching="matching-expression"/>
<!-- closing tags for each parent of the level -->
</configuration>
</get-configuration>
</rpc>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:
object-type[name='regular-expression']
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.
|
Operator |
Matches |
|---|---|
|
|
One instance of any character. |
|
|
Zero or more instances of the immediately preceding term. |
|
|
One or more instances of the immediately preceding term. |
|
|
Zero or one instance of the immediately preceding term. |
|
|
One of the terms that appear on either side of the pipe operator. |
|
|
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. |
|
|
The end of a line. |
|
|
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, |
|
|
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.
<rpc-reply xmlns:junos="URL">
<configuration attributes>
<!-- opening tags for each parent of the parent level -->
<parent-level>
<first-matching-object>
<!-- child tag elements for the first object -->
</first-matching-object>
<second-matching-object>
<!-- child tag elements for the second object -->
</second-matching-object>
<!-- additional instances of the object -->
</parent-level>
<!-- closing tags for each parent of the object type -->
</configuration>
</rpc-reply>
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:
-
Request a Specific Number of Configuration Objects Using the Junos XML Protocol
-
Request 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
-
Specifying the Output Format for Configuration Data in a Junos XML Protocol Session
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:
<rpc>
<get-configuration>
<configuration>
<interfaces matching="interface[name='ge-.*']" count="2" recurse="false"/>
</configuration>
</get-configuration>
</rpc>The Junos XML protocol server returns the identifiers for the requested objects.
<rpc-reply xmlns:junos="URL">
<configuration junos:changed-seconds="1758308076" junos:changed-localtime="2025-09-19 11:54:36 PDT">
<interfaces>
<interface junos:position="1" junos:total="2">
<name>ge-0/0/0</name>
</interface>
<interface junos:position="2" junos:total="2">
<name>ge-0/0/1</name>
</interface>
</interfaces>
</configuration>
</rpc-reply>