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

📄 xregex.texi

📁 正则表达式库
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo@c %**start of header@setfilename regex.info@settitle Regex@c %**end of header@c \\{fill-paragraph} works better (for me, anyway) if the text in the@c source file isn't indented.@paragraphindent 2@c Define a new index for our magic constants.@defcodeindex cn@c Put everything in one index (arbitrarily chosen to be the concept index).@syncodeindex cn cp@syncodeindex ky cp@syncodeindex pg cp@syncodeindex tp cp@syncodeindex vr cp@c Here is what we use in the Info `dir' file:@c * Regex: (regex).	Regular expression library.@ifinfoThis file documents the GNU regular expression library.Copyright (C) 1992, 1993 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies.@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries a copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that thesection entitled ``GNU General Public License'' is included exactly asin the original, and provided that the entire resulting derived work isdistributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that the section entitled ``GNU General Public License'' may beincluded in a translation approved by the Free Software Foundationinstead of in the original English.@end ifinfo@titlepage@title Regex@subtitle edition 0.12a@subtitle 19 September 1992@author Kathryn A. Hargreaves@author Karl Berry@page@vskip 0pt plus 1filllCopyright @copyright{} 1992 Free Software Foundation.Permission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that thesection entitled ``GNU General Public License'' is included exactly asin the original, and provided that the entire resulting derived work isdistributed under the terms of a permission notice identical to thisone.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that the section entitled ``GNU General Public License'' may beincluded in a translation approved by the Free Software Foundationinstead of in the original English.@end titlepage@ifinfo@node Top, Overview, (dir), (dir)@top Regular Expression LibraryThis manual documents how to program with the GNU regular expressionlibrary.  This is edition 0.12a of the manual, 19 September 1992.The first part of this master menu lists the major nodes in this Infodocument, including the index.  The rest of the menu lists all thelower level nodes in the document.@menu* Overview::* Regular Expression Syntax::* Common Operators::* GNU Operators::* GNU Emacs Operators::* What Gets Matched?::* Programming with Regex::* Copying::			Copying and sharing Regex.* Index::			General index. --- The Detailed Node Listing ---Regular Expression Syntax* Syntax Bits::* Predefined Syntaxes::* Collating Elements vs. Characters::* The Backslash Character::Common Operators* Match-self Operator::			Ordinary characters.* Match-any-character Operator::	.* Concatenation Operator::		Juxtaposition.* Repetition Operators::		*  +  ? @{@}* Alternation Operator::		|* List Operators::			[...]  [^...]* Grouping Operators::			(...)* Back-reference Operator::		\digit* Anchoring Operators::			^  $Repetition Operators    * Match-zero-or-more Operator::  ** Match-one-or-more Operator::   +* Match-zero-or-one Operator::   ?* Interval Operators::           @{@}List Operators (@code{[} @dots{} @code{]} and @code{[^} @dots{} @code{]})* Character Class Operators::   [:class:]* Range Operator::          start-endAnchoring Operators    * Match-beginning-of-line Operator::  ^* Match-end-of-line Operator::        $GNU Operators* Word Operators::* Buffer Operators::Word Operators* Non-Emacs Syntax Tables::* Match-word-boundary Operator::	\b* Match-within-word Operator::		\B* Match-beginning-of-word Operator::	\<* Match-end-of-word Operator::		\>* Match-word-constituent Operator::	\w* Match-non-word-constituent Operator::	\WBuffer Operators    * Match-beginning-of-buffer Operator::	\`* Match-end-of-buffer Operator::	\'GNU Emacs Operators* Syntactic Class Operators::Syntactic Class Operators* Emacs Syntax Tables::* Match-syntactic-class Operator::	\sCLASS* Match-not-syntactic-class Operator::  \SCLASSProgramming with Regex* GNU Regex Functions::* POSIX Regex Functions::* BSD Regex Functions::GNU Regex Functions* GNU Pattern Buffers::         The re_pattern_buffer type.* GNU Regular Expression Compiling::  re_compile_pattern ()* GNU Matching::                re_match ()* GNU Searching::               re_search ()* Matching/Searching with Split Data::  re_match_2 (), re_search_2 ()* Searching with Fastmaps::     re_compile_fastmap ()* GNU Translate Tables::        The `translate' field.* Using Registers::             The re_registers type and related fns.* Freeing GNU Pattern Buffers::  regfree ()POSIX Regex Functions* POSIX Pattern Buffers::		The regex_t type.* POSIX Regular Expression Compiling::	regcomp ()* POSIX Matching::			regexec ()* Reporting Errors::			regerror ()* Using Byte Offsets::			The regmatch_t type.* Freeing POSIX Pattern Buffers::	regfree ()BSD Regex Functions* BSD Regular Expression Compiling::	re_comp ()* BSD Searching::			re_exec ()@end menu@end ifinfo@node Overview, Regular Expression Syntax, Top, Top@chapter OverviewA @dfn{regular expression} (or @dfn{regexp}, or @dfn{pattern}) is a textstring that describes some (mathematical) set of strings.  A regexp@var{r} @dfn{matches} a string @var{s} if @var{s} is in the set ofstrings described by @var{r}.Using the Regex library, you can:@itemize @bullet@itemsee if a string matches a specified pattern as a whole, and @itemsearch within a string for a substring matching a specified pattern.@end itemizeSome regular expressions match only one string, i.e., the set theydescribe has only one member.  For example, the regular expression@samp{foo} matches the string @samp{foo} and no others.  Other regularexpressions match more than one string, i.e., the set they describe hasmore than one member.  For example, the regular expression @samp{f*}matches the set of strings made up of any number (including zero) of@samp{f}s.  As you can see, some characters in regular expressions matchthemselves (such as @samp{f}) and some don't (such as @samp{*}); theones that don't match themselves instead let you specify patterns thatdescribe many different strings.To either match or search for a regular expression with the Regexlibrary functions, you must first compile it with a Regex patterncompiling function.  A @dfn{compiled pattern} is a regular expressionconverted to the internal format used by the library functions.  Onceyou've compiled a pattern, you can use it for matching or searching anynumber of times.The Regex library consists of two source files: @file{regex.h} and@file{regex.c}.  @pindex regex.h@pindex regex.cRegex provides three groups of functions with which you can operate onregular expressions.  One group---the @sc{gnu} group---is more powerfulbut not completely compatible with the other two, namely the @sc{posix}and Berkeley @sc{unix} groups; its interface was designed specificallyfor @sc{gnu}.  The other groups have the same interfaces as do theregular expression functions in @sc{posix} and Berkeley@sc{unix}.We wrote this chapter with programmers in mind, not users ofprograms---such as Emacs---that use Regex.  We describe the Regexlibrary in its entirety, not how to write regular expressions that aparticular program understands.@node Regular Expression Syntax, Common Operators, Overview, Top@chapter Regular Expression Syntax@cindex regular expressions, syntax of@cindex syntax of regular expressions@dfn{Characters} are things you can type.  @dfn{Operators} are things ina regular expression that match one or more characters.  You composeregular expressions from operators, which in turn you specify using oneor more characters.Most characters represent what we call the match-self operator, i.e.,they match themselves; we call these characters @dfn{ordinary}.  Othercharacters represent either all or parts of fancier operators; e.g.,@samp{.} represents what we call the match-any-character operator(which, no surprise, matches (almost) any character); we call thesecharacters @dfn{special}.  Two different things determine whatcharacters represent what operators:@enumerate@itemthe regular expression syntax your program has told the Regex library torecognize, and@itemthe context of the character in the regular expression.@end enumerateIn the following sections, we describe these things in more detail.@menu* Syntax Bits::* Predefined Syntaxes::* Collating Elements vs. Characters::* The Backslash Character::@end menu@node Syntax Bits, Predefined Syntaxes,  , Regular Expression Syntax@section Syntax Bits @cindex syntax bitsIn any particular syntax for regular expressions, some characters arealways special, others are sometimes special, and others are neverspecial.  The particular syntax that Regex recognizes for a givenregular expression depends on the value in the @code{syntax} field ofthe pattern buffer of that regular expression.You get a pattern buffer by compiling a regular expression.  @xref{GNUPattern Buffers}, and @ref{POSIX Pattern Buffers}, for more informationon pattern buffers.  @xref{GNU Regular Expression Compiling}, @ref{POSIXRegular Expression Compiling}, and @ref{BSD Regular ExpressionCompiling}, for more information on compiling.Regex considers the value of the @code{syntax} field to be a collectionof bits; we refer to these bits as @dfn{syntax bits}.  In most cases,they affect what characters represent what operators.  We describe themeanings of the operators to which we refer in @ref{Common Operators},@ref{GNU Operators}, and @ref{GNU Emacs Operators}.  For reference, here is the complete list of syntax bits, in alphabeticalorder:@table @code@cnindex RE_BACKSLASH_ESCAPE_IN_LIST@item RE_BACKSLASH_ESCAPE_IN_LISTSIf this bit is set, then @samp{\} inside a list (@pxref{List Operators}quotes (makes ordinary, if it's special) the following character; ifthis bit isn't set, then @samp{\} is an ordinary character inside lists.(@xref{The Backslash Character}, for what `\' does outside of lists.)@cnindex RE_BK_PLUS_QM@item RE_BK_PLUS_QMIf this bit is set, then @samp{\+} represents the match-one-or-moreoperator and @samp{\?} represents the match-zero-or-more operator; ifthis bit isn't set, then @samp{+} represents the match-one-or-moreoperator and @samp{?} represents the match-zero-or-one operator.  Thisbit is irrelevant if @code{RE_LIMITED_OPS} is set.@cnindex RE_CHAR_CLASSES@item RE_CHAR_CLASSESIf this bit is set, then you can use character classes in lists; if thisbit isn't set, then you can't.@cnindex RE_CONTEXT_INDEP_ANCHORS@item RE_CONTEXT_INDEP_ANCHORSIf this bit is set, then @samp{^} and @samp{$} are special anywhere outsidea list; if this bit isn't set, then these characters are special only incertain contexts.  @xref{Match-beginning-of-line Operator}, and@ref{Match-end-of-line Operator}.@cnindex RE_CONTEXT_INDEP_OPS@item RE_CONTEXT_INDEP_OPSIf this bit is set, then certain characters are special anywhere outsidea list; if this bit isn't set, then those characters are special only insome contexts and are ordinary elsewhere.  Specifically, if this bitisn't set then @samp{*}, and (if the syntax bit @code{RE_LIMITED_OPS}

⌨️ 快捷键说明

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