There should be a "regsplit" or "regexplode" primitive
that splits a string on matches of a regular
expression, like Perl's "split" function. e.g.:
"potassium" "[aeiou]+" regsplit
would return:
{"p", "t", "ss", "m"}
regsplit[ str:str str:pat -- list:matches ]
"\r#&$%^\r" var! marker
str @ pat @ marker @ REG_ALL
marker @ explode_array
;
regsplit[ str:str str:pat -- list:matches ]
pat @ "^\(.*\)%s\(.*\)$" fmtstring pat !
{ }list var! out
begin
str @ pat @ 0 regexp if
dup 1 [] out @ []<- out !
2 [] dup strlen str @ strlen = if
1 strcut swap pop
then
str !
else
str @ out @ []<- exit
then
repeat
;
Logged In: YES
user_id=6331
Is possible the marker string in my previous comment should be
different, so as not to have any &s or stuff that regsub may
expand. I just wrote that off the top of my head. Idea is to use a
merker string that is highly unlikely to occur in the string you
expect to split.
Logged In: YES
user_id=7718
Still, it'd be quicker to implement it in the server.
Natty, do you consider this one done enough? Or should it
stay open and in the feature requests?
Added REGSPLIT and REGSPLIT_NOEMPTY in FB7.