Subst

Subst — applies a substitution pattern to a string of a given length.

Synopsis

static Regex.Subst(pattern, subject, length?=-1)
    

Arguments

pattern

A substitution pattern, in the form s/pattern/substitution/flags.

subject

The subject string on which the substitution will be made.

length

The length of the subject string. Entering -1 (the default) for this parameter will cause the length of the subject string to be automatically computed.

Returns

On success, returns the new string with the substitutions applied. On failure, an error list with three elements:

  • car(errlist) = a numeric return code from the failing function

  • cadr(errlist) = a character position in the pattern where the error occurred, or 0.

  • caddr(errlist) = an error message, as a human-readable string

Examples

String replacement:

Gamma> x = "This is a test of my test system"
"This is a test of my test system"
Gamma> Regex.Subst("s/test/build/g", x)
"This is a build of my build system"

To surround all words with parentheses:

Gamma> Regex.Subst ("s/(\\w+)/\\($1\\)/g", "This is a test!");
"(This) (is) (a) (test)!"

See Also

Match