RegSub - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


StringTools

  

RegSub

  

perform regular expression substitutions

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

RegSub( pattern, text, template )

Parameters

pattern

-

string; regular expression

text

-

string; text to use

template

-

string; copy as output

Description

• 

The RegSub( pattern, text, template ) function performs regular expression search and replace on text. RegSub tests whether the string text matches the regular expression pattern. If a match occurs, the string template is copied as the output, but substrings can be replaced with the portion of text that matched pattern as follows.

  

The substring & is replaced with the portion of text that matched the entire regular expression pattern. If d is a single digit, then the substring \d is replaced with the substring of text matching the d-th parenthesized subexpression of pattern.

  

If text does not match pattern, the value FAIL is returned.

  

Note: RegSub is a very low-level procedure. For most applications, StringTools[RegSubs] is easier to use.

• 

This function is part of the StringTools package, and so it can be used in the form RegSub(..) only after executing the command with(StringTools). However, it can always be accessed through the long form of the command by using the form StringTools[RegSub](..).

• 

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

withStringTools:

RegSub((a)),abc,gu\\1v\\2

guava

(1)

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

abbbcd-abbbc

(2)

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

abcd-bc-d

(3)

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

effgz-effgz-

(4)

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

effgz-effgz-

(5)

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

Maple is Canadian

(6)

See Also

Regular_Expressions

string

StringTools

StringTools[Escape]

StringTools[RegMatch]

StringTools[RegSubs]

StringTools[Substitute]

StringTools[SubstituteAll]