in reply to splitting

If you put a grouping term like '(delimeter)'in the regular expression for split it will return that group as well as the normal splitted parts.

This code assigns @a the normal split return variables, but the regex will also return the pattern matched between the '()' so @a becomes (text,delimeter,text,delimeter,text)
$str = "text delimeter text delimeter text"; @a = split(/\s+(delimeter)\s+/, $str);
If I tried: @a = split(/(\s+)(delimeter)(\s+)/, $str); Then @a is (text,' ',delimeter,' ',text,' ',delimeter,' ',text);

Replies are listed 'Best First'.
RE: Re: splitting
by snowcrash (Friar) on Apr 27, 2000 at 10:52 UTC
    $str = "text delimeter text delimeter text"; @a = split(/\s+(delimeter)\s+/, $str);
    Note that this won't work if the delimiter (called "delimeter" here :) is at the end or at the beginning of your string.
    probably, replacing the \s+ with \s* in the regexp would be better. But then, if "delimeter" was at the beginning of the string, you'd have an empty string as the first element of your array.