Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Automation Scripting User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

regex() Function (SLAX and XSLT)

date_range 13-Jan-21

Namespaces

content_copy zoom_out_map
http://xml.juniper.net/junos/commit-scripts/1.0
http://xml.libslax.org/slax

SLAX Syntax

content_copy zoom_out_map
var $result = prefix:regex(pattern, string);

XSLT Syntax

content_copy zoom_out_map
<xsl:variable name="result" select="prefix:regex(pattern, string)"/>

Description

Evaluate a regular expression against a given string argument and return any matches. This function requires two arguments: the regular expression and the string to which the regular expression is compared.

The prefix associated with the namespace URI should be defined in the prefix-to-namespace mapping in the style sheet.

Parameters

pattern

Regular expression that is evaluated against the string argument.

string

String within which to search for matches of the specified regular expression.

Return Value

result

Array of strings that match the given regex pattern within the string argument.

Usage Examples

In the following example, the regex pattern consists of four distinct groups. The first group consists of the entire expression. The three subsequent groups are each of the parentheses–enclosed expressions within the main expression. The results for each jcs:regex() function call contain an array of the matches of the regex pattern to each of the specified strings.

content_copy zoom_out_map
var $pattern = "([0-9]+)(:*)([a-z]*)";
var $a = jcs:regex($pattern, "123:xyz");
var $b = jcs:regex($pattern, "r2d2");
var $c = jcs:regex($pattern, "test999!!!");
 
$a[1] == "123:xyz"    # string that matches the full reg expression
$a[2] == "123"        # ([0-9]+)
$a[3] == ":"          # (:*)
$a[4] == "xyz"        # ([a-z]*)
$b[1] == "2d"         # string that matches the full reg expression
$b[2] == "2"          # ([0-9]+)
$b[3] == ""           # (:*)   [empty match]
$b[4] == "d"          # ([a-z]*)
$c[1] == "999"        # string that matches the full reg expression
$c[2] == "999"        # ([0-9]+)
$c[3] == ""           # (:*)   [empty match]
$c[4] == ""           # ([a-z]*)   [empty match]

Release Information

Function introduced in Junos OS Release 7.6

Support for the slax namespace http://xml.libslax.org/slax added in Junos OS Release 12.2.

footer-navigation