RegSplit - Maple Help

StringTools

 RegSplit
 split a string on a regular expression

 Calling Sequence RegSplit( pattern, text )

Parameters

 pattern - string; regular expression text - string; string to split

Description

 • The RegSplit(pattern, text) command splits a string text at substrings matching the regular expression pattern. The sequence of substrings of text that remain after substrings of text that match pattern have been elided is returned.
 • Splitting the empty string on any regular expression yields the expression sequence NULL.
 • If the regular expression pattern matches the empty string, an exception is raised.
 • Empty strings may result when adjacent matches to pattern occur within text. These can be removed as shown in the examples below.
 • Use StringTools[Split] to split a string at any of a set of characters. (See the examples, below.) Although this can be accomplished with RegSplit, StringTools[Split] is more efficient for this special case.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{RegSplit}\left("ab","xabyabz"\right)$
 ${"x"}{,}{"y"}{,}{"z"}$ (1)
 > $\mathrm{RegSplit}\left("ab","xababz"\right)$
 ${"x"}{,}{""}{,}{"z"}$ (2)
 > $\mathrm{RegSplit}\left("\left(a|b\right)","xabyabz"\right)$
 ${"x"}{,}{""}{,}{"y"}{,}{""}{,}{"z"}$ (3)
 > $\mathrm{RegSplit}\left("\left(\\.|,|;\right)","The Levi-Civita theorem provides a straightforward test for separability; however, because it is only a local characterization, it does not, in general, aid in the determination of separable coordinates."\right)$
 ${"The Levi-Civita theorem provides a straightforward test for separability"}{,}{"however"}{,}{"because it is only a local characterization"}{,}{"it does not"}{,}{"in general"}{,}{"aid in the determination of separable coordinates"}$ (4)
 > $\mathrm{RegSplit}\left("\left[a-e\right]*","xabyabz"\right)$
 > $\mathrm{RegMatch}\left("\left[a-e\right]*",""\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{RegSplit}\left("\left[a-e\right]+","xabyabz"\right)$
 ${"x"}{,}{"y"}{,}{"z"}$ (6)
 > $\mathrm{RegSplit}\left("\left[a-e\right]","xabyabz"\right)$
 ${"x"}{,}{""}{,}{"y"}{,}{""}{,}{"z"}$ (7)
 > $\mathrm{RegSplit}\left("\left[x-z\right]","xabyabz"\right)$
 ${""}{,}{"ab"}{,}{"ab"}$ (8)
 > $\mathrm{Split}\left("xabyabz","abcde"\right)$
 $\left[{"x"}{,}{""}{,}{"y"}{,}{""}{,}{"z"}\right]$ (9)

You can remove unwanted empty strings as follows.

 > $\mathrm{remove}\left(\mathrm{type},\left[\mathrm{RegSplit}\right]\left("ab","abxabyabz"\right),""\right)$
 $\left[{"x"}{,}{"y"}{,}{"z"}\right]$ (10)