 RegSubs - Maple Help

# Online Help

###### All Products    Maple    MapleSim

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.)
 • 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{RegSubs}\left("\left(\left(a\right)\right)"="gu\\1v\\2","abc"\right)$
 ${"guavabc"}$ (1)
 > $\mathrm{RegSubs}\left("\left(\left[abc\right]*\right)d"="&-\\1","abbbcd"\right)$
 ${"abbbcd-abbbc"}$ (2)
 > $\mathrm{RegSubs}\left("a\left(\left[bc\right]*\right)\left(c*d\right)"="&-\\1-\\2","abcd"\right)$
 ${"abcd-bc-d"}$ (3)
 > $\mathrm{RegSubs}\left("\left(bc+d|ef*g.|h?i\left(j+k\right)\right)"="&-\\1-\\2","effgz"\right)$
 ${"effgz-effgz-"}$ (4)
 > $\mathrm{RegSubs}\left("\left(bc+d|ef*g.|h?i\left(j|k\right)\right)"="&-\\1-\\2","reffgz"\right)$
 ${"reffgz-effgz-"}$ (5)
 > $\mathrm{RegSubs}\left("\left(.*\right)c\left(anad\left[ai\right]\right)\left(.*\right)"="\\1C\\2\\3","Maple is canadian"\right)$
 ${"Maple is Canadian"}$ (6)
 > $\mathrm{RegSubs}\left("\left[ \t\right]+"="","Some text \t\t with extra \t space."\right)$
 ${"Some text with extra space."}$ (7)

 See Also