STRING::SPLITRE 1g 2024-03-26 laplante@plcb.ca GOWEB/STRING — Split String Using Regular Expression


title: “STRING::SPLITRE” version: “1.0.0” date: 2024-03-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/STRING”


Name

string::splitre Split String Using Regular Expression

Synopsis

string::splitre(string, re/.../[, nbmatch: int])
splitre(string, re/.../[, nbmatch: int])
string::splitRe(string, re/.../[, nbmatch: int])
splitRe(string, re/.../[, nbmatch: int])

Description

The splitre function splits a string using a regular expression as the separator and returns an array of substrings or nil.

Behavior of nbmatch:


Examples

res={{
    splitre(re/a/, "banana"); "\n";
    splitre(re/a/, "banana", nbmatch:0); "\n";
    splitre(re/a/, "banana", nbmatch:1); "\n";
    splitre(re/a/, "banana", nbmatch:2); "\n";
    splitre(re/z+/, "pizza"); "\n";
    splitre(re/z+/, "pizza",nbmatch:0); "\n";
    splitre(re/z+/, "pizza",nbmatch:1); "\n";
    splitre(re/z+/, "pizza",nbmatch:2); "\n";
}}.

Returns:

res=["b","n","n",""]
[]
["banana"]
["b","nana"]
["pi","a"]
[]
["pizza"]
["pi","a"]

Author

laplante@plcb.ca

See Also


Version