regsub(n) Tcl Built-In Commands regsub(n) _________________________________________________________________ NAME regsub - Perform substitutions based on regular expression pattern matching SYNOPSIS regsub ?_s_w_i_t_c_h_e_s? _e_x_p _s_t_r_i_n_g _s_u_b_S_p_e_c _v_a_r_N_a_m_e _________________________________________________________________ DESCRIPTION This command matches the regular expression _e_x_p against _s_t_r_i_n_g, and it copies _s_t_r_i_n_g to the variable whose name is given by _v_a_r_N_a_m_e. If there is a match, then while copying _s_t_r_i_n_g to _v_a_r_N_a_m_e the portion of _s_t_r_i_n_g that matched _e_x_p is replaced with _s_u_b_S_p_e_c. If _s_u_b_S_p_e_c contains a ``&'' or ``\0'', then it is replaced in the substitution with the portion of _s_t_r_i_n_g that matched _e_x_p. If _s_u_b_S_p_e_c contains a ``\_n'', where _n is a digit between 1 and 9, then it is replaced in the substitution with the portion of _s_t_r_i_n_g that matched the _n-th parenthesized subexpression of _e_x_p. Addi- tional backslashes may be used in _s_u_b_S_p_e_c to prevent special interpretation of ``&'' or ``\0'' or ``\_n'' or backslash. The use of backslashes in _s_u_b_S_p_e_c tends to interact badly with the Tcl parser's use of backslashes, so it's generally safest to enclose _s_u_b_S_p_e_c 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 _s_t_r_i_n_g that match _e_x_p are found and substitution is performed for each of these ranges. Without this switch only the first match- ing range is found and substituted. If -all is specified, then ``&'' and ``\_n'' sequences are handled for each substitution using the informa- tion from the corresponding match. -nocase Upper-case characters in _s_t_r_i_n_g will be converted to lower-case before matching against _e_x_p; how- ever, substitutions specified by _s_u_b_S_p_e_c use the original unconverted form of _s_t_r_i_n_g. -- Marks the end of switches. The argument follow- ing this one will be treated as _e_x_p even if it starts with a -. The command returns a count of the number of matching ranges that were found and replaced. See the manual entry for Tcl Last change: 7.4 1 regsub(n) Tcl Built-In Commands regsub(n) regexp for details on the interpretation of regular expres- sions. KEYWORDS match, pattern, regular expression, substitute Tcl Last change: 7.4 2