📄 regexp.3
字号:
'\"'\" Copyright (c) 1994 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) RegExp.3 1.9 96/08/26 12:59:48'\" .so man.macros.TH Tcl_RegExpMatch 3 7.4 Tcl "Tcl Library Procedures".BS.SH NAMETcl_RegExpMatch, Tcl_RegExpCompile, Tcl_RegExpExec, Tcl_RegExpRange \- Pattern matching with regular expressions.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spint\fBTcl_RegExpMatch\fR(\fIinterp\fR, \fIstring\fR, \fIpattern\fR).spTcl_RegExp\fBTcl_RegExpCompile\fR(\fIinterp\fR, \fIpattern\fR).spint\fBTcl_RegExpExec\fR(\fIinterp\fR, \fIregexp\fR, \fIstring\fR, \fIstart\fR).sp\fBTcl_RegExpRange\fR(\fIregexp\fR, \fIindex\fR, \fIstartPtr\fR, \fIendPtr\fR).SH ARGUMENTS.AS Tcl_Interp *interp.AP Tcl_Interp *interp inTcl interpreter to use for error reporting..AP char *string inString to check for a match with a regular expression..AP char *pattern inString in the form of a regular expression pattern..AP Tcl_RegExp regexp inCompiled regular expression. Must have been returned previouslyby \fBTcl_RegExpCompile\fR..AP char *start inIf \fIstring\fR is just a portion of some other string, this argumentidentifies the beginning of the larger string.If it isn't the same as \fIstring\fR, then no \fB^\fR matcheswill be allowed..AP int index inSpecifies which range is desired: 0 means the range of the entirematch, 1 or greater means the range that matched a parenthesizedsub-expression..AP char **startPtr outThe address of the first character in the range is stored here, orNULL if there is no such range..AP char **endPtr outThe address of the character just after the last one in the rangeis stored here, or NULL if there is no such range..BE.SH DESCRIPTION.PP\fBTcl_RegExpMatch\fR determines whether its \fIpattern\fR argumentmatches \fIregexp\fR, where \fIregexp\fR is interpretedas a regular expression using the same rules as for the\fBregexp\fR Tcl command.If there is a match then \fBTcl_RegExpMatch\fR returns 1.If there is no match then \fBTcl_RegExpMatch\fR returns 0.If an error occurs in the matching process (e.g. \fIpattern\fRis not a valid regular expression) then \fBTcl_RegExpMatch\fRreturns \-1 and leaves an error message in \fIinterp->result\fR..PP\fBTcl_RegExpCompile\fR, \fBTcl_RegExpExec\fR, and \fBTcl_RegExpRange\fRprovide lower-level access to the regular expression pattern matcher.\fBTcl_RegExpCompile\fR compiles a regular expression string intothe internal form used for efficient pattern matching.The return value is a token for this compiled form, which can beused in subsequent calls to \fBTcl_RegExpExec\fR or \fBTcl_RegExpRange\fR.If an error occurs while compiling the regular expression then\fBTcl_RegExpCompile\fR returns NULL and leaves an error messagein \fIinterp->result\fR.Note: the return value from \fBTcl_RegExpCompile\fR is only validup to the next call to \fBTcl_RegExpCompile\fR; it is not safe toretain these values for long periods of time..PP\fBTcl_RegExpExec\fR executes the regular expression pattern matcher.It returns 1 if \fIstring\fR contains a range of characters thatmatch \fIregexp\fR, 0 if no match is found, and\-1 if an error occurs.In the case of an error, \fBTcl_RegExpExec\fR leaves an errormessage in \fIinterp->result\fR.When searching a string for multiple matches of a pattern,it is important to distinguish between the start of the originalstring and the start of the current search.For example, when searching for the second occurrence of amatch, the \fIstring\fR argument might point to the characterjust after the first match; however, it is important for thepattern matcher to know that this is not the start of the entire string,so that it doesn't allow \fB^\fR atoms in the pattern to match.The \fIstart\fR argument provides this information by pointingto the start of the overall string containing \fIstring\fR.\fIStart\fR will be less than or equal to \fIstring\fR; if itis less than \fIstring\fR then no \fB^\fR matches will be allowed..PP\fBTcl_RegExpRange\fR may be invoked after \fBTcl_RegExpExec\fRreturns; it provides detailed information about what ranges ofthe string matched what parts of the pattern.\fBTcl_RegExpRange\fR returns a pair of pointers in \fI*startPtr\fRand \fI*endPtr\fR that identify a range of characters inthe source string for the most recent call to \fBTcl_RegExpExec\fR.\fIIndex\fR indicates which of several ranges is desired:if \fIindex\fR is 0, information is returned about the overall rangeof characters that matched the entire pattern; otherwise,information is returned about the range of characters that matched the\fIindex\fR'th parenthesized subexpression within the pattern.If there is no range corresponding to \fIindex\fR then NULLis stored in \fI*firstPtr\fR and \fI*lastPtr\fR..SH KEYWORDSmatch, pattern, regular expression, string, subexpression
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -