Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

split() Function (SLAX and XSLT)

Namespaces

SLAX Syntax

XSLT Syntax

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(:).

returns:

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.

returns:

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.