STRING::SPLITRE 1g 2024-03-26 laplante@plcb.ca GOWEB/STRING — Split String Using Regular Expressiontitle: “STRING::SPLITRE” version: “1.0.0” date: 2024-03-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/STRING”
string::splitre Split String Using Regular Expression
string::splitre(string, re/.../[, nbmatch: int])
splitre(string, re/.../[, nbmatch: int])
string::splitRe(string, re/.../[, nbmatch: int])
splitRe(string, re/.../[, nbmatch: int])
The splitre function splits a string using a regular expression as the separator and returns an array of substrings or nil.
nbmatch:nbmatch > 0 — At most n substrings; the last substring will contain the unsplit remainder.nbmatch == 0 — Returns nil (zero substrings).nbmatch < 0 — Returns all possible substrings (no limit).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"]
laplante@plcb.ca