regsub.n
来自「tcl是工具命令语言」· N 代码 · 共 123 行
N
123 行
'\"'\" Copyright (c) 1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\" Copyright (c) 2000 Scriptics Corporation.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: regsub.n,v 1.9 2003/02/20 15:33:02 dkf Exp $'\" .so man.macros.TH regsub n 8.3 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEregsub \- Perform substitutions based on regular expression pattern matching.SH SYNOPSIS.VS 8.4\fBregsub \fR?\fIswitches\fR? \fIexp string subSpec \fR?\fIvarName\fR?.VE 8.4.BE.SH DESCRIPTION.PPThis command matches the regular expression \fIexp\fR against\fIstring\fR,.VS 8.4and either copies \fIstring\fR to the variable whose name isgiven by \fIvarName\fR or returns \fIstring\fR if \fIvarName\fR is notpresent..VE 8.4(Regular expression matching is described in the \fBre_syntax\fRreference page.)If there is a match, then while copying \fIstring\fR to \fIvarName\fR.VS 8.4(or to the result of this command if \fIvarName\fR is not present).VE 8.4the portion of \fIstring\fR thatmatched \fIexp\fR is replaced with \fIsubSpec\fR.If \fIsubSpec\fR contains a ``&'' or ``\e0'', then it is replacedin the substitution with the portion of \fIstring\fR thatmatched \fIexp\fR.If \fIsubSpec\fR contains a ``\e\fIn\fR'', where \fIn\fR is a digitbetween 1 and 9, then it is replaced in the substitution withthe portion of \fIstring\fR that matched the \fIn\fR-thparenthesized subexpression of \fIexp\fR.Additional backslashes may be used in \fIsubSpec\fR to prevent specialinterpretation of ``&'' or ``\e0'' or ``\e\fIn\fR'' orbackslash.The use of backslashes in \fIsubSpec\fR tends to interact badlywith the Tcl parser's use of backslashes, so it's generallysafest to enclose \fIsubSpec\fR in braces if it includesbackslashes..LPIf the initial arguments to \fBregsub\fR start with \fB\-\fR thenthey are treated as switches. The following switches arecurrently supported:.TP 10\fB\-all\fRAll ranges in \fIstring\fR that match \fIexp\fR are found andsubstitution is performed for each of these ranges.Without this switch only the firstmatching range is found and substituted.If \fB\-all\fR is specified, then ``&'' and ``\e\fIn\fR''sequences are handled for each substitution using the informationfrom the corresponding match..TP 15\fB\-expanded\fREnables use of the expanded regular expression syntax wherewhitespace and comments are ignored. This is the same as specifyingthe \fB(?x)\fR embedded option (see the \fBre_syntax\fR manual page)..TP 15\fB\-line\fREnables newline-sensitive matching. By default, newline is acompletely ordinary character with no special meaning. With thisflag, `[^' bracket expressions and `.' never match newline, `^'matches an empty string after any newline in addition to its normalfunction, and `$' matches an empty string before any newline inaddition to its normal function. This flag is equivalent tospecifying both \fB\-linestop\fR and \fB\-lineanchor\fR, or the\fB(?n)\fR embedded option (see the \fBre_syntax\fR manual page)..TP 15\fB\-linestop\fRChanges the behavior of `[^' bracket expressions and `.' so that theystop at newlines. This is the same as specifying the \fB(?p)\fRembedded option (see the \fBre_syntax\fR manual page)..TP 15\fB\-lineanchor\fRChanges the behavior of `^' and `$' (the ``anchors'') so they match thebeginning and end of a line respectively. This is the same asspecifying the \fB(?w)\fR embedded option (see the \fBre_syntax\fRmanual page)..TP 10\fB\-nocase\fRUpper-case characters in \fIstring\fR will be converted to lower-casebefore matching against \fIexp\fR; however, substitutions specifiedby \fIsubSpec\fR use the original unconverted form of \fIstring\fR..TP 10\fB\-start\fR \fIindex\fRSpecifies a character index offset into the string to startmatching the regular expression at. When using this switch, `^'will not match the beginning of the line, and \\A will stillmatch the start of the string at \fIindex\fR.\fIindex\fR will be constrained to the bounds of the input string..TP 10\fB\-\|\-\fRMarks the end of switches. The argument following this one willbe treated as \fIexp\fR even if it starts with a \fB\-\fR..PP.VS 8.4If \fIvarName\fR is supplied, the command returns a count of thenumber of matching ranges that were found and replaced, otherwise thestring after replacement is returned..VE 8.4See the manual entry for \fBregexp\fR for details on the interpretationof regular expressions..SH "SEE ALSO"regexp(n), re_syntax(n).SH KEYWORDSmatch, pattern, regular expression, substitute
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?