regex() Function (SLAX and XSLT)
Namespaces
http://xml.juniper.net/junos/commit-scripts/1.0 http://xml.libslax.org/slax
SLAX Syntax
var $result = prefix:regex(pattern, string);
XSLT Syntax
<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.
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.