Top
Systemwalker Operation Manager  Reference Guide
FUJITSU Software

15.2.17 regsub (Perform Substitutions based on Regular Expression Pattern Matching)

Description

Performs substitutions based on regular expression pattern matching.

Synopsis

regsub [-all] exp string subspec varname

Options

-all

Specify to substitute all portions that matched a regular expression. If omitted, only the first matching portion is substituted.

exp

Specify the regular expression that identifies the portion to substitute.

string

Specify the string to be replaced.

subspec

Specify the string to replace. The string to replace must be enclosed in braces ({}). To include "\" or "&" in the string to replace, they must be written "\\" or "\&", respectively.

varname

Specify the name of the variable to store the string that was replaced.

Point

A regular expression is a shorthand for describing the structure of a string using symbols. This command searches the string specified by string for the portion that matches the structure represented in the regular expression exp. If there is a match, it replaces it with the string specified by subspec and stores in the variable whose name is given by varname.

For how to write a regular expression, see "15.1.4 Regular Expression".

Return Values

0:

Not matched.

1:

Matched.

Example

The following example replaces all spaces between strings with commas.

set text "a b c d"
regsub -all " " $text {,} result
puts $result

Execution Results/Output Format

a,b,c,d