perform regular expression substitutions - Maple Help

Online Help

All Products    Maple    MapleSim


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

StringTools[RegSubs] - perform regular expression substitutions

Calling Sequence

RegSubs( env, text )

Parameters

env

-

string = string; substitution to make

text

-

string; text to substitute into

Description

• 

The RegSubs(env,text) command replaces each occurrence of a substring matching the left-hand side of env with the right-hand side of env in the string text.

  

If no substring of text matches the left-hand side of env, then text is returned unchanged.

• 

This procedure is closely related to StringTools[RegSub], but provides a more intuitive interface. The chief difference between the two is that RegSubs effects all relevant substitutions (serially), while StringTools[RegSub] performs a single substitution. Also, the left-hand side of env cannot match an empty substring of text. (An exception is raised in this case.)

Examples

withStringTools:

RegSubs((a))=gu\1v\2,abc

guavabc

(1)

RegSubs([abc]*)d=&-\1,abbbcd

abbbcd-abbbc

(2)

RegSubsa([bc]*)(c*d)=&-\1-\2,abcd

abcd-bc-d

(3)

RegSubs(bc+d$|ef*g.|h?i(j+k))=&-\1-\2,effgz

effgz-effgz-

(4)

RegSubs(bc+d$|ef*g.|h?i(j|k))=&-\1-\2,reffgz

reffgz-effgz-

(5)

RegSubs(.*)c(anad[ai])(.*)=\1C\2\3,Maple is canadian

Maple is Canadian

(6)

RegSubs[ ]+= ,Some text with extra space.

Some text with extra space.

(7)

See Also

Regular_Expressions, string, StringTools, StringTools[RegMatch], StringTools[RegSub], StringTools[Substitute], StringTools[SubstituteAll]


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