split a string on a regular expression - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Pattern Matching : StringTools/RegSplit

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.

Examples

withStringTools:

RegSplitab,xabyabz

x,y,z

(1)

RegSplitab,xababz

x,,z

(2)

RegSplit(a|b),xabyabz

x,,y,,z

(3)

RegSplit(\.|,|;),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.

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)

RegSplit[a-e]*,xabyabz

Error, (in StringTools:-RegSplit) empty string would match

RegMatch[a-e]*,

true

(5)

RegSplit[a-e]+,xabyabz

x,y,z

(6)

RegSplit[a-e],xabyabz

x,,y,,z

(7)

RegSplit[x-z],xabyabz

,ab,ab

(8)

Splitxabyabz,abcde

x,,y,,z

(9)

You can remove unwanted empty strings as follows.

removetype,RegSplitab,abxabyabz,

x,y,z

(10)

See Also

Regular_Expressions, string, StringTools, StringTools[RegMatch], StringTools[RegSubs], StringTools[Split]


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam