⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regex.3

📁 Newlib 嵌入式 C库 标准实现代码
💻 3
📖 第 1 页 / 共 2 页
字号:
.\" Copyright (c) 1992, 1993, 1994 Henry Spencer..\" Copyright (c) 1992, 1993, 1994.\"	The Regents of the University of California.  All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" Henry Spencer..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)regex.3	8.4 (Berkeley) 3/20/94.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.9 2001/10/01 16:08:58 ru Exp $.\".Dd March 20, 1994.Dt REGEX 3.Os.Sh NAME.Nm regcomp ,.Nm regexec ,.Nm regerror ,.Nm regfree.Nd regular-expression library.Sh LIBRARY.Lb libc.Sh SYNOPSIS.In sys/types.h.In regex.h.Ft int.Fn regcomp "regex_t *preg" "const char *pattern" "int cflags".Ft int.Fo regexec.Fa "const regex_t *preg" "const char *string".Fa "size_t nmatch" "regmatch_t pmatch[]" "int eflags".Fc.Ft size_t.Fo regerror.Fa "int errcode" "const regex_t *preg".Fa "char *errbuf" "size_t errbuf_size".Fc.Ft void.Fn regfree "regex_t *preg".Sh DESCRIPTIONThese routines implement.St -p1003.2regular expressions.Pq Do RE Dc Ns s ;see.Xr re_format 7 ..Fn Regcompcompiles an RE written as a string into an internal form,.Fn regexecmatches that internal form against a string and reports results,.Fn regerrortransforms error codes from either into human-readable messages,and.Fn regfreefrees any dynamically-allocated storage used by the internal formof an RE..PpThe header.Aq Pa regex.hdeclares two structure types,.Ft regex_tand.Ft regmatch_t ,the former for compiled internal forms and the latter for match reporting.It also declares the four functions,a type.Ft regoff_t ,and a number of constants with names starting with.Dq Dv REG_ ..Pp.Fn Regcompcompiles the regular expression contained in the.Fa patternstring,subject to the flags in.Fa cflags ,and places the results in the.Ft regex_tstructure pointed to by.Fa preg ..Fa Cflagsis the bitwise OR of zero or more of the following flags:.Bl -tag -width REG_EXTENDED.It Dv REG_EXTENDEDCompile modern.Pq Dq extendedREs,rather than the obsolete.Pq Dq basicREs thatare the default..It Dv REG_BASICThis is a synonym for 0,provided as a counterpart to.Dv REG_EXTENDEDto improve readability..It Dv REG_NOSPECCompile with recognition of all special characters turned off.All characters are thus considered ordinary,so the.Dq REis a literal string.This is an extension,compatible with but not specified by.St -p1003.2 ,and should be used withcaution in software intended to be portable to other systems..Dv REG_EXTENDEDand.Dv REG_NOSPECmay not be usedin the same call to.Fn regcomp ..It Dv REG_ICASECompile for matching that ignores upper/lower case distinctions.See.Xr re_format 7 ..It Dv REG_NOSUBCompile for matching that need only report success or failure,not what was matched..It Dv REG_NEWLINECompile for newline-sensitive matching.By default, newline is a completely ordinary character with no specialmeaning in either REs or strings.With this flag,.Ql [^bracket expressions and.Ql .\&never match newline,a.Ql ^\&anchor matches the null string after any newline in the stringin addition to its normal function,and the.Ql $\&anchor matches the null string before any newline in thestring in addition to its normal function..It Dv REG_PENDThe regular expression ends,not at the first NUL,but just before the character pointed to by the.Va re_endpmember of the structure pointed to by.Fa preg .The.Va re_endpmember is of type.Ft "const char *" .This flag permits inclusion of NULs in the RE;they are considered ordinary characters.This is an extension,compatible with but not specified by.St -p1003.2 ,and should be used withcaution in software intended to be portable to other systems..El.PpWhen successful,.Fn regcompreturns 0 and fills in the structure pointed to by.Fa preg .One member of that structure(other than.Va re_endp )is publicized:.Va re_nsub ,of type.Ft size_t ,contains the number of parenthesized subexpressions within the RE(except that the value of this member is undefined if the.Dv REG_NOSUBflag was used).If.Fn regcompfails, it returns a non-zero error code;see.Sx DIAGNOSTICS ..Pp.Fn Regexecmatches the compiled RE pointed to by.Fa pregagainst the.Fa string ,subject to the flags in.Fa eflags ,and reports results using.Fa nmatch ,.Fa pmatch ,and the returned value.The RE must have been compiled by a previous invocation of.Fn regcomp .The compiled form is not altered during execution of.Fn regexec ,so a single compiled RE can be used simultaneously by multiple threads..PpBy default,the NUL-terminated string pointed to by.Fa stringis considered to be the text of an entire line, minus any terminatingnewline.The.Fa eflagsargument is the bitwise OR of zero or more of the following flags:.Bl -tag -width REG_STARTEND.It Dv REG_NOTBOLThe first character ofthe stringis not the beginning of a line, so the.Ql ^\&anchor should not match before it.This does not affect the behavior of newlines under.Dv REG_NEWLINE ..It Dv REG_NOTEOLThe NUL terminatingthe stringdoes not end a line, so the.Ql $\&anchor should not match before it.This does not affect the behavior of newlines under.Dv REG_NEWLINE ..It Dv REG_STARTENDThe string is considered to start at.Fa string+.Fa pmatch Ns [0]. Ns Va rm_soand to have a terminating NUL located at.Fa string+.Fa pmatch Ns [0]. Ns Va rm_eo(there need not actually be a NUL at that location),regardless of the value of.Fa nmatch .See below for the definition of.Fa pmatchand.Fa nmatch .This is an extension,compatible with but not specified by.St -p1003.2 ,and should be used withcaution in software intended to be portable to other systems.Note that a non-zero.Va rm_sodoes not imply.Dv REG_NOTBOL ;.Dv REG_STARTENDaffects only the location of the string,not how it is matched..El.PpSee.Xr re_format 7for a discussion of what is matched in situations where an RE or aportion thereof could match any of several substrings of.Fa string ..PpNormally,.Fn regexecreturns 0 for success and the non-zero code.Dv REG_NOMATCHfor failure.Other non-zero error codes may be returned in exceptional situations;see.Sx DIAGNOSTICS ..PpIf.Dv REG_NOSUBwas specified in the compilation of the RE,or if.Fa nmatchis 0,.Fn regexecignores the.Fa pmatchargument (but see below for the case where.Dv REG_STARTENDis specified).Otherwise,.Fa pmatchpoints to an array of.Fa nmatchstructures of type.Ft regmatch_t .Such a structure has at least the members.Va rm_soand.Va rm_eo ,both of type.Ft regoff_t(a signed arithmetic type at least as large as an.Ft off_tand a.Ft ssize_t ) ,containing respectively the offset of the first character of a substringand the offset of the first character after the end of the substring.Offsets are measured from the beginning of the.Fa stringargument given to.Fn regexec .An empty substring is denoted by equal offsets,both indicating the character following the empty substring..PpThe 0th member of the.Fa pmatcharray is filled in to indicate what substring of.Fa stringwas matched by the entire RE.Remaining members report what substring was matched by parenthesizedsubexpressions within the RE;member.Va ireports subexpression.Va i ,with subexpressions counted (starting at 1) by the order of their openingparentheses in the RE, left to right.Unused entries in the array (corresponding either to subexpressions thatdid not participate in the match at all, or to subexpressions that do notexist in the RE (that is,.Va i>.Fa preg Ns -> Ns Va re_nsub ) )have both.Va rm_soand

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -