Assuming your delimiters are
' ',',', or ';',for example, doing
gives us:perl -e'print join "!!",split /([ ,;])/,"This sentence contains, in he +re, a comma; and there's a semicolon clause\n";'
This!! !!sentence!! !!contains!!,!!!! !!in!! !!here!!,!!!! !!a!! !!comma!!;!!!! !!and!! !!there's!! !!a!! !!semicolon!! !!clauseThis trick uses the fact that
join "{some delimiter string}",@array
returns the contents of @array, separated by the delimiter string.
As you can see, things like ", " confuse it, so you might want to use a + inside the parentheses if you can afford to collect multiple separators into one array slot.
That's a bit better; now we get:perl -e'print join "!!",split /([ ,;]+)/,"This sentence contains, in h +ere, a comma; and there's a semicolon clause\n";'
This!! !!sentence!! !!contains!!, !!in!! !!here!!, !!a!! !!comma!!; !!and!! !!there's!! !!a!! !!semicolon!! !!clauseHope this helps...
In reply to Re: splitting
by rmgiroux
in thread splitting
by Eugene
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |