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

📄 regex.3

📁 Newlib 嵌入式 C库 标准实现代码
💻 3
📖 第 1 页 / 共 2 页
字号:
.Va rm_eoset to -1.If a subexpression participated in the match several times,the reported substring is the last one it matched.(Note, as an example in particular, that when the RE.Ql "(b*)+"matches.Ql bbb ,the parenthesized subexpression matches each of the three.So Li b Sc Ns sand thenan infinite number of empty strings following the last.Ql b ,so the reported substring is one of the empties.).PpIf.Dv REG_STARTENDis specified,.Fa pmatchmust point to at least one.Ft regmatch_t(even if.Fa nmatchis 0 or.Dv REG_NOSUBwas specified),to hold the input offsets for.Dv REG_STARTEND .Use for output is still entirely controlled by.Fa nmatch ;if.Fa nmatchis 0 or.Dv REG_NOSUBwas specified,the value of.Fa pmatch Ns [0]will not be changed by a successful.Fn regexec ..Pp.Fn Regerrormaps a non-zero.Fa errcodefrom either.Fn regcompor.Fn regexecto a human-readable, printable message.If.Fa pregis.No non\- Ns Dv NULL ,the error code should have arisen from use ofthe.Ft regex_tpointed to by.Fa preg ,and if the error code came from.Fn regcomp ,it should have been the result from the most recent.Fn regcompusing that.Ft regex_t ..No ( Fn Regerrormay be able to supply a more detailed message using informationfrom the.Ft regex_t . ).Fn Regerrorplaces the NUL-terminated message into the buffer pointed to by.Fa errbuf ,limiting the length (including the NUL) to at most.Fa errbuf_sizebytes.If the whole message won't fit,as much of it as will fit before the terminating NUL is supplied.In any case,the returned value is the size of buffer needed to hold the wholemessage (including terminating NUL).If.Fa errbuf_sizeis 0,.Fa errbufis ignored but the return value is still correct..PpIf the.Fa errcodegiven to.Fn regerroris first ORed with.Dv REG_ITOA ,the.Dq messagethat results is the printable name of the error code,e.g.\&.Dq Dv REG_NOMATCH ,rather than an explanation thereof.If.Fa errcodeis.Dv REG_ATOI ,then.Fa pregshall be.No non\- Ns Dv NULLand the.Va re_endpmember of the structure it points tomust point to the printable name of an error code;in this case, the result in.Fa errbufis the decimal digits ofthe numeric value of the error code(0 if the name is not recognized)..Dv REG_ITOAand.Dv REG_ATOIare intended primarily as debugging facilities;they are extensions,compatible with but not specified by.St -p1003.2 ,and should be used withcaution in software intended to be portable to other systems.Be warned also that they are considered experimental and changes are possible..Pp.Fn Regfreefrees any dynamically-allocated storage associated with the compiled REpointed to by.Fa preg .The remaining.Ft regex_tis no longer a valid compiled REand the effect of supplying it to.Fn regexecor.Fn regerroris undefined..PpNone of these functions references global variables except for tablesof constants;all are safe for use from multiple threads if the arguments are safe..Sh IMPLEMENTATION CHOICESThere are a number of decisions that.St -p1003.2leaves up to the implementor,either by explicitly saying.Dq undefinedor by virtue of them beingforbidden by the RE grammar.This implementation treats them as follows..PpSee.Xr re_format 7for a discussion of the definition of case-independent matching..PpThere is no particular limit on the length of REs,except insofar as memory is limited.Memory usage is approximately linear in RE size, and largely insensitiveto RE complexity, except for bounded repetitions.See.Sx BUGSfor one short RE using themthat will run almost any system out of memory..PpA backslashed character other than one specifically given a magic meaningby.St -p1003.2(such magic meanings occur only in obsolete.Bq Dq basicREs)is taken as an ordinary character..PpAny unmatched.Ql [\&is a.Dv REG_EBRACKerror..PpEquivalence classes cannot begin or end bracket-expression ranges.The endpoint of one range cannot begin another..Pp.Dv RE_DUP_MAX ,the limit on repetition counts in bounded repetitions, is 255..PpA repetition operator.Ql ( ?\& ,.Ql *\& ,.Ql +\& ,or bounds)cannot follow anotherrepetition operator.A repetition operator cannot begin an expression or subexpressionor follow.Ql ^\&or.Ql |\& ..Pp.Ql |\&cannot appear first or last in a (sub)expression or after another.Ql |\& ,i.e. an operand of.Ql |\&cannot be an empty subexpression.An empty parenthesized subexpression,.Ql "()" ,is legal and matches anempty (sub)string.An empty string is not a legal RE..PpA.Ql {\&followed by a digit is considered the beginning of bounds for abounded repetition, which must then follow the syntax for bounds.A.Ql {\&.Em notfollowed by a digit is considered an ordinary character..Pp.Ql ^\&and.Ql $\&beginning and ending subexpressions in obsolete.Pq Dq basicREs are anchors, not ordinary characters..Sh SEE ALSO.Xr grep 1 ,.Xr re_format 7.Pp.St -p1003.2 ,sections 2.8 (Regular Expression Notation)andB.5 (C Binding for Regular Expression Matching)..Sh DIAGNOSTICSNon-zero error codes from.Fn regcompand.Fn regexecinclude the following:.Pp.Bl -tag -width REG_ECOLLATE -compact.It Dv REG_NOMATCH.Fn regexecfailed to match.It Dv REG_BADPATinvalid regular expression.It Dv REG_ECOLLATEinvalid collating element.It Dv REG_ECTYPEinvalid character class.It Dv REG_EESCAPE.Ql \eapplied to unescapable character.It Dv REG_ESUBREGinvalid backreference number.It Dv REG_EBRACKbrackets.Ql "[ ]"not balanced.It Dv REG_EPARENparentheses.Ql "( )"not balanced.It Dv REG_EBRACEbraces.Ql "{ }"not balanced.It Dv REG_BADBRinvalid repetition count(s) in.Ql "{ }".It Dv REG_ERANGEinvalid character range in.Ql "[ ]".It Dv REG_ESPACEran out of memory.It Dv REG_BADRPT.Ql ?\& ,.Ql *\& ,or.Ql +\&operand invalid.It Dv REG_EMPTYempty (sub)expression.It Dv REG_ASSERTcan't happen - you found a bug.It Dv REG_INVARGinvalid argument, e.g. negative-length string.El.Sh HISTORYOriginally written by.An Henry Spencer .Altered for inclusion in the.Bx 4.4distribution..Sh BUGSThis is an alpha release with known defects.Please report problems..PpThe back-reference code is subtle and doubts linger about its correctnessin complex cases..Pp.Fn Regexecperformance is poor.This will improve with later releases..Fa Nmatchexceeding 0 is expensive;.Fa nmatchexceeding 1 is worse..Fn Regexecis largely insensitive to RE complexity.Em exceptthat backreferences are massively expensive.RE length does matter; in particular, there is a strong speed bonusfor keeping RE length under about 30 characters,with most special characters counting roughly double..Pp.Fn Regcompimplements bounded repetitions by macro expansion,which is costly in time and space if counts are largeor bounded repetitions are nested.An RE like, say,.Ql "((((a{1,100}){1,100}){1,100}){1,100}){1,100}"will (eventually) run almost any existing machine out of swap space..PpThere are suspected problems with response to obscure error conditions.Notably,certain kinds of internal overflow,produced only by truly enormous REs or by multiply nested bounded repetitions,are probably not handled well..PpDue to a mistake in.St -p1003.2 ,things like.Ql "a)b"are legal REs because.Ql )\&isa special character only in the presence of a previous unmatched.Ql (\& .This can't be fixed until the spec is fixed..PpThe standard's definition of back references is vague.For example, does.Ql "a\e(\e(b\e)*\e2\e)*d"match.Ql "abbbd" ?Until the standard is clarified,behavior in such cases should not be relied on..PpThe implementation of word-boundary matching is a bit of a kludge,and bugs may lurk in combinations of word-boundary matching and anchoring.

⌨️ 快捷键说明

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