Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
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

split() 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 $substrings = prefix:split(expression, string, <limit>);

XSLT Syntax

content_copy zoom_out_map
<xsl:variable name="substrings" select="prefix:split(expression, string, <limit>)"/>

Description

Split a string into an array of substrings delimited by a regular expression pattern. If the optional integer argument limit is specified, the function splits the entire string into limit number of substrings. If there are more than limit number of matches, the substrings include the first limit-1 matches as well as the remaining portion of the original string for the last match.

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

Parameters

expression

Regular expression pattern used as the delimiter.

limit

(Optional) Number of substrings into which to break the original string.

string

Original string.

Return Value

$substrings

Array of limit number of substrings. If limit is not specified, the result array size is equal to the number of substrings extracted from the original string as determined by the specified delimiter.

Usage Examples

In the following example, the original string is "123:abc:456:xyz:789". The jcs:split() function breaks this string into substrings that are delimited by the regular expression pattern, which in this case is a colon(:). The optional parameter limit is not specified, so the function returns an array containing all the substrings that are bounded by the delimiter(:).

content_copy zoom_out_map
var $pattern = "(:)";
var $substrings = jcs:split($pattern, "123:abc:456:xyz:789");

returns:

content_copy zoom_out_map
$substrings[1] == "123"
$substrings[2] == "abc"
$substrings[3] == "456"
$substrings[4] == "xyz"
$substrings[5] == "789"

The following example uses the same original string and regular expression as the previous example, but in this case, the optional parameter limit is included. Specifying limit=2 causes the function to return an array containing only two substrings. The substrings include the first match, which is "123" (the same first match as in the previous example), and a second match, which is the remaining portion of the original string after the first occurrence of the delimiter.

content_copy zoom_out_map
var $pattern = "(:)";
var $substrings = jcs:split($pattern, "123:abc:456:xyz:789", 2);

returns:

content_copy zoom_out_map
$substrings[1] == "123"
$substrings[2] == "abc:456:xyz:789"

Release Information

Function introduced in Junos OS Release 8.4

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

footer-navigation