DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

regsub(1tcl)


regsub -- perform substitutions based on regular expression pattern matching

Synopsis

regsub [switches] exp string subSpec varName

Description

This command matches the regular expression exp against string, and copies string to the variable whose name is given by varName. The command returns 1 if there is a match and 0 if there isn't. If there is a match, then while copying string to varName, the portion of string that matches exp is replaced with subSpec. If subSpec contains a ``&'' or ``\0'', then it is replaced in the substitution with the portion of string that matches exp. If subSpec contains a ``\n'', where n is a digit between 1 and 9, then it is replaced in the substitution with the portion of string that matches the nth parenthesized subexpression of exp. Additional backslashes may be used in subSpec to prevent special interpretation of ``&'' or ``\0'' or ``\n'' or backslash. The use of backslashes in subSpec tends to interact badly with the Tcl parser's use of backslashes, so it is generally safest to enclose subSpec in braces if it includes backslashes.

If the initial arguments to regexp start with ``-'' then they are treated as switches. The following switches are currently supported:


-all
All ranges in string that match exp are found and substitution is performed for each of these ranges. Without this switch only the first matching range is found and substituted. If -all is specified, then ``&'' and ``\n'' sequences are handled for each substitution using the information from the corresponding match.

-nocase
Upper-case characters in string are converted to lowercase before matching against exp; however, substitutions specified by subSpec use the original unconverted form of string.

--
Marks the end of switches. The argument following this one is treated as exp even if it starts with a ``-''.
See the manual entry for regexp(1tcl) for details on the interpretation of regular expressions.

References


25 April 2004
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004