Navigation
Guide That Contains This Content
[+] Expand All
[-] Collapse All
     

    Related Documentation

     

    split() Function (jcs and slax Namespaces)

    Namespaces

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

    SLAX Syntax

    var $substrings = prefix:split(expression, string, <limit>);

    XSLT Syntax

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

    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.

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

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

    returns:

    $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.

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

    returns:

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

    Related Documentation

     

    Published: 2013-03-05