home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #1 / MONSTER.ISO / prog / gen / regex011.taz / regex011 / regex-0.11 / doc / regex.info < prev    next >
Encoding:
GNU Info File  |  1992-09-17  |  115.5 KB  |  2,817 lines

  1. This is Info file regex.info, produced by Makeinfo-1.47 from the input
  2. file regex.texi.
  3.  
  4.   This file documents the GNU regular expression library.
  5.  
  6.   Copyright (C) 1992 Free Software Foundation, Inc.
  7.  
  8.   Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.   Permission is granted to copy and distribute modified versions of this
  13. manual under the conditions for verbatim copying, provided also that the
  14. section entitled "GNU General Public License" is included exactly as in
  15. the original, and provided that the entire resulting derived work is
  16. distributed under the terms of a permission notice identical to this
  17. one.
  18.  
  19.   Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the section entitled "GNU General Public License"
  22. may be included in a translation approved by the Free Software
  23. Foundation instead of in the original English.
  24.  
  25. 
  26. File: regex.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
  27.  
  28. Introduction
  29. ************
  30.  
  31.   This manual documents how to program with the GNU regular expression
  32. library.  This is edition 0.11 of the manual, 15 September 1992.
  33.  
  34.   The first part of this master menu lists the major nodes in this Info
  35. document, including the index.  The rest of the menu lists all the
  36. lower level nodes in the document.
  37.  
  38. * Menu:
  39.  
  40. * Overview::
  41. * Regular Expression Syntax::
  42. * Common Operators::
  43. * GNU Operators::
  44. * GNU Emacs Operators::
  45. * What Gets Matched?::
  46. * Programming with Regex::
  47. * Copying::                     Copying and sharing Regex.
  48. * Index::                       General index.
  49.  -- The Detailed Node Listing --
  50.  
  51. Regular Expression Syntax
  52.  
  53. * Syntax Bits::
  54. * Predefined Syntaxes::
  55. * Collating Elements vs. Characters::
  56. * The Backslash Character::
  57.  
  58. Common Operators
  59.  
  60. * Match-self Operator::                 Ordinary characters.
  61. * Match-any-character Operator::        .
  62. * Concatenation Operator::              Juxtaposition.
  63. * Repetition Operators::                *  +  ? {}
  64. * Alternation Operator::                |
  65. * List Operators::                      [...]  [^...]
  66. * Grouping Operators::                  (...)
  67. * Back-reference Operator::             \digit
  68. * Anchoring Operators::                 ^  $
  69.  
  70. Repetition Operators
  71.  
  72. * Match-zero-or-more Operator::  *
  73. * Match-one-or-more Operator::   +
  74. * Match-zero-or-one Operator::   ?
  75. * Interval Operators::           {}
  76.  
  77. List Operators (`[' ... `]' and `[^' ... `]')
  78.  
  79. * Character Class Operators::   [:class:]
  80. * Range Operator::          start-end
  81.  
  82. Anchoring Operators
  83.  
  84. * Match-beginning-of-line Operator::  ^
  85. * Match-end-of-line Operator::        $
  86.  
  87. GNU Operators
  88.  
  89. * Word Operators::
  90. * Buffer Operators::
  91.  
  92. Word Operators
  93.  
  94. * Non-Emacs Syntax Tables::
  95. * Match-word-boundary Operator::        \b
  96. * Match-within-word Operator::          \B
  97. * Match-beginning-of-word Operator::    \<
  98. * Match-end-of-word Operator::          \>
  99. * Match-word-constituent Operator::     \w
  100. * Match-non-word-constituent Operator:: \W
  101.  
  102. Buffer Operators
  103.  
  104. * Match-beginning-of-buffer Operator::  \`
  105. * Match-end-of-buffer Operator::        \'
  106.  
  107. GNU Emacs Operators
  108.  
  109. * Syntactic Class Operators::
  110.  
  111. Syntactic Class Operators
  112.  
  113. * Emacs Syntax Tables::
  114. * Match-syntactic-class Operator::      \sCLASS
  115. * Match-not-syntactic-class Operator::  \SCLASS
  116.  
  117. Programming with Regex
  118.  
  119. * GNU Regex Functions::
  120. * POSIX Regex Functions::
  121. * BSD Regex Functions::
  122.  
  123. GNU Regex Functions
  124.  
  125. * GNU Pattern Buffers::         The re_pattern_buffer type.
  126. * GNU Regular Expression Compiling::  re_compile_pattern ()
  127. * GNU Matching::                re_match ()
  128. * GNU Searching::               re_search ()
  129. * Matching/Searching with Split Data::  re_match_2 (), re_search_2 ()
  130. * Searching with Fastmaps::     re_compile_fastmap ()
  131. * GNU Translate Tables::        The `translate' field.
  132. * Using Registers::             The re_registers type and related fns.
  133. * Freeing GNU Pattern Buffers::  regfree ()
  134.  
  135. POSIX Regex Functions
  136.  
  137. * POSIX Pattern Buffers::               The regex_t type.
  138. * POSIX Regular Expression Compiling::  regcomp ()
  139. * POSIX Matching::                      regexec ()
  140. * Reporting Errors::                    regerror ()
  141. * Using Byte Offsets::                  The regmatch_t type.
  142. * Freeing POSIX Pattern Buffers::       regfree ()
  143.  
  144. BSD Regex Functions
  145.  
  146. * BSD Regular Expression Compiling::    re_comp ()
  147. * BSD Searching::                       re_exec ()
  148.  
  149. 
  150. File: regex.info,  Node: Overview,  Next: Regular Expression Syntax,  Prev: Top,  Up: Top
  151.  
  152. Overview
  153. ********
  154.  
  155.   A "regular expression" (or "regexp", or "pattern") is a text string
  156. that describes some (mathematical) set of strings.  A regexp R
  157. "matches" a string S if S is in the set of strings described by R.
  158.  
  159.   Using the Regex library, you can:
  160.  
  161.    * see if a string matches a specified pattern as a whole, and
  162.  
  163.    * search within a string for a substring matching a specified
  164.      pattern.
  165.  
  166.   Some regular expressions match only one string, i.e., the set they
  167. describe has only one member.  For example, the regular expression
  168. `foo' matches the string `foo' and no others.  Other regular
  169. expressions match more than one string, i.e., the set they describe has
  170. more than one member.  For example, the regular expression `f*' matches
  171. the set of strings made up of any number (including zero) of `f's.  As
  172. you can see, some characters in regular expressions match themselves
  173. (such as `f') and some don't (such as `*'); the ones that don't match
  174. themselves instead let you specify patterns that describe many
  175. different strings.
  176.  
  177.   To either match or search for a regular expression with the Regex
  178. library functions, you must first compile it with a Regex pattern
  179. compiling function.  A "compiled pattern" is a regular expression
  180. converted to the internal format used by the library functions.  Once
  181. you've compiled a pattern, you can use it for matching or searching any
  182. number of times.
  183.  
  184.   The Regex library consists of two source files: `regex.h' and
  185. `regex.c'. Regex provides three groups of functions with which you can
  186. operate on regular expressions.  One group--the GNU group--is more
  187. powerful but not completely compatible with the other two, namely the
  188. POSIX and Berkeley UNIX groups; its interface was designed specifically
  189. for GNU.  The other groups have the same interfaces as do the regular
  190. expression functions in POSIX and Berkeley UNIX.
  191.  
  192.   We wrote this chapter with programmers in mind, not users of
  193. programs--such as Emacs--that use Regex.  We describe the Regex library
  194. in its entirety, not how to write regular expressions that a particular
  195. program understands.
  196.  
  197. 
  198. File: regex.info,  Node: Regular Expression Syntax,  Next: Common Operators,  Prev: Overview,  Up: Top
  199.  
  200. Regular Expression Syntax
  201. *************************
  202.  
  203.   "Characters" are things you can type.  "Operators" are things in a
  204. regular expression that match one or more characters.  You compose
  205. regular expressions from operators, which in turn you specify using one
  206. or more characters.
  207.  
  208.   Most characters represent what we call the match-self operator, i.e.,
  209. they match themselves; we call these characters "ordinary".  Other
  210. characters represent either all or parts of fancier operators; e.g.,
  211. `.' represents what we call the match-any-character operator (which, no
  212. surprise, matches (almost) any character); we call these characters
  213. "special".  Two different things determine what characters represent
  214. what operators:
  215.  
  216.   1. the regular expression syntax your program has told the Regex
  217.      library to recognize, and
  218.  
  219.   2. the context of the character in the regular expression.
  220.  
  221.   In the following sections, we describe these things in more detail.
  222.  
  223. * Menu:
  224.  
  225. * Syntax Bits::
  226. * Predefined Syntaxes::
  227. * Collating Elements vs. Characters::
  228. * The Backslash Character::
  229.  
  230. 
  231. File: regex.info,  Node: Syntax Bits,  Next: Predefined Syntaxes,  Up: Regular Expression Syntax
  232.  
  233. Syntax Bits
  234. ===========
  235.  
  236.   In any particular syntax for regular expressions, some characters are
  237. always special, others are sometimes special, and others are never
  238. special.  The particular syntax that Regex recognizes for a given
  239. regular expression depends on the value in the `syntax' field of the
  240. pattern buffer of that regular expression.
  241.  
  242.   You get a pattern buffer by compiling a regular expression.  *Note
  243. GNU Pattern Buffers::, and *Note POSIX Pattern Buffers::, for more
  244. information on pattern buffers.  *Note GNU Regular Expression
  245. Compiling::, *Note POSIX Regular Expression Compiling::, and *Note BSD
  246. Regular Expression Compiling::, for more information on compiling.
  247.  
  248.   Regex considers the value of the `syntax' field to be a collection of
  249. bits; we refer to these bits as "syntax bits".  In most cases, they
  250. affect what characters represent what operators.  We describe the
  251. meanings of the operators to which we refer in *Note Common Operators::,
  252. *Note GNU Operators::, and *Note GNU Emacs Operators::.
  253.  
  254.   For reference, here is the complete list of syntax bits, in
  255. alphabetical order:
  256.  
  257. `RE_BACKSLASH_ESCAPE_IN_LISTS'
  258.      If this bit is set, then `\' inside a list (*note List Operators::.
  259.      quotes (makes ordinary, if it's special) the following character;
  260.      if this bit isn't set, then `\' is an ordinary character inside
  261.      lists. (*Note The Backslash Character::, for what `\' does outside
  262.      of lists.)
  263.  
  264. `RE_BK_PLUS_QM'
  265.      If this bit is set, then `\+' represents the match-one-or-more
  266.      operator and `\?' represents the match-zero-or-more operator; if
  267.      this bit isn't set, then `+' represents the match-one-or-more
  268.      operator and `?' represents the match-zero-or-one operator.  This
  269.      bit is irrelevant if `RE_LIMITED_OPS' is set.
  270.  
  271. `RE_CHAR_CLASSES'
  272.      If this bit is set, then you can use character classes in lists;
  273.      if this bit isn't set, then you can't.
  274.  
  275. `RE_CONTEXT_INDEP_ANCHORS'
  276.      If this bit is set, then `^' and `$' are special anywhere outside
  277.      a list; if this bit isn't set, then these characters are special
  278.      only in certain contexts.  *Note Match-beginning-of-line
  279.      Operator::, and *Note Match-end-of-line Operator::.
  280.  
  281. `RE_CONTEXT_INDEP_OPS'
  282.      If this bit is set, then certain characters are special anywhere
  283.      outside a list; if this bit isn't set, then those characters are
  284.      special only in some contexts and are ordinary elsewhere. 
  285.      Specifically, if this bit isn't set then `*', and (if the syntax
  286.      bit `RE_LIMITED_OPS' isn't set) `+' and `?' (or `\+' and `\?',
  287.      depending on the syntax bit `RE_BK_PLUS_QM') represent repetition
  288.      operators only if they're not first in a regular expression or
  289.      just after an open-group or alternation operator.  The same holds
  290.      for `{' (or `\{', depending on the syntax bit `RE_NO_BK_BRACES') if
  291.      it is the beginning of a valid interval and the syntax bit
  292.      `RE_INTERVALS' is set.
  293.  
  294. `RE_CONTEXT_INVALID_OPS'
  295.      If this bit is set, then repetition and alternation operators
  296.      can't be in certain positions within a regular expression. 
  297.      Specifically, the regular expression is invalid if it has:
  298.  
  299.         * a repetition operator first in the regular expression or just
  300.           after a match-beginning-of-line, open-group, or alternation
  301.           operator; or
  302.  
  303.         * an alternation operator first or last in the regular
  304.           expression, just before a match-end-of-line operator, or just
  305.           after an alternation or open-group operator.
  306.  
  307.      If this bit isn't set, then you can put the characters
  308.      representing the repetition and alternation characters anywhere in
  309.      a regular expression. Whether or not they will in fact be
  310.      operators in certain positions depends on other syntax bits.
  311.  
  312. `RE_DOT_NEWLINE'
  313.      If this bit is set, then the match-any-character operator matches
  314.      a newline; if this bit isn't set, then it doesn't.
  315.  
  316. `RE_DOT_NOT_NULL'
  317.      If this bit is set, then the match-any-character operator doesn't
  318.      match a null character; if this bit isn't set, then it does.
  319.  
  320. `RE_INTERVALS'
  321.      If this bit is set, then Regex recognizes interval operators; if
  322.      this bit isn't set, then it doesn't.
  323.  
  324. `RE_LIMITED_OPS'
  325.      If this bit is set, then Regex doesn't recognize the
  326.      match-one-or-more, match-zero-or-one or alternation operators; if
  327.      this bit isn't set, then it does.
  328.  
  329. `RE_NEWLINE_ALT'
  330.      If this bit is set, then newline represents the alternation
  331.      operator; if this bit isn't set, then newline is ordinary.
  332.  
  333. `RE_NO_BK_BRACES'
  334.      If this bit is set, then `{' represents the open-interval operator
  335.      and `}' represents the close-interval operator; if this bit isn't
  336.      set, then `\{' represents the open-interval operator and `\}'
  337.      represents the close-interval operator.  This bit is relevant only
  338.      if `RE_INTERVALS' is set.
  339.  
  340. `RE_NO_BK_PARENS'
  341.      If this bit is set, then `(' represents the open-group operator and
  342.      `)' represents the close-group operator; if this bit isn't set,
  343.      then `\(' represents the open-group operator and `\)' represents
  344.      the close-group operator.
  345.  
  346. `RE_NO_BK_REFS'
  347.      If this bit is set, then Regex doesn't recognize `\'DIGIT as the
  348.      back reference operator; if this bit isn't set, then it does.
  349.  
  350. `RE_NO_BK_VBAR'
  351.      If this bit is set, then `|' represents the alternation operator;
  352.      if this bit isn't set, then `\|' represents the alternation
  353.      operator.  This bit is irrelevant if `RE_LIMITED_OPS' is set.
  354.  
  355. `RE_NO_EMPTY_RANGES'
  356.      If this bit is set, then a regular expression with a range whose
  357.      ending point collates lower than its starting point is invalid; if
  358.      this bit isn't set, then Regex considers such a range to be empty.
  359.  
  360. `RE_UNMATCHED_RIGHT_PAREN_ORD'
  361.      If this bit is set and the regular expression has no matching
  362.      open-group operator, then Regex considers what would otherwise be
  363.      a close-group operator (based on how `RE_NO_BK_PARENS' is set) to
  364.      match `)'.
  365.  
  366. 
  367. File: regex.info,  Node: Predefined Syntaxes,  Next: Collating Elements vs. Characters,  Prev: Syntax Bits,  Up: Regular Expression Syntax
  368.  
  369. Predefined Syntaxes
  370. ===================
  371.  
  372.   If you're programming with Regex, you can set a pattern buffer's
  373. (*note GNU Pattern Buffers::., and *Note POSIX Pattern Buffers::)
  374. `syntax' field either to an arbitrary combination of syntax bits (*note
  375. Syntax Bits::.) or else to the configurations defined by Regex. These
  376. configurations define the syntaxes used by certain programs--GNU Emacs,
  377. POSIX Awk, traditional Awk, Grep, Egrep--in addition to syntaxes for
  378. POSIX basic and extended regular expressions.
  379.  
  380.   The predefined syntaxes--taken directly from `regex.h'--are:
  381.  
  382.      #define RE_SYNTAX_EMACS 0
  383.      
  384.      #define RE_SYNTAX_AWK                                                   \
  385.        (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL                       \
  386.         | RE_NO_BK_PARENS            | RE_NO_BK_REFS                         \
  387.         | RE_NO_BK_VAR               | RE_NO_EMPTY_RANGES                    \
  388.         | RE_UNMATCHED_RIGHT_PAREN_ORD)
  389.      
  390.      #define RE_SYNTAX_POSIX_AWK                                             \
  391.        (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
  392.      
  393.      #define RE_SYNTAX_GREP                                                  \
  394.        (RE_BK_PLUS_QM              | RE_CHAR_CLASSES                         \
  395.         | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS                            \
  396.         | RE_NEWLINE_ALT)
  397.      
  398.      #define RE_SYNTAX_EGREP                                                 \
  399.        (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS                    \
  400.         | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE                    \
  401.         | RE_NEWLINE_ALT       | RE_NO_BK_PARENS                             \
  402.         | RE_NO_BK_VBAR)
  403.      
  404.      #define RE_SYNTAX_POSIX_EGREP                                           \
  405.        (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
  406.      
  407.      #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
  408.      
  409.      /* Syntax bits common to both basic and extended POSIX regex syntax.  */
  410.      #define _RE_SYNTAX_POSIX_COMMON                                         \
  411.        (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL              \
  412.         | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
  413.      
  414.      #define RE_SYNTAX_POSIX_BASIC                                           \
  415.        (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
  416.      
  417.      /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
  418.         RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
  419.         isn't minimal, since other operators, such as \`, aren't disabled.  */
  420.      #define RE_SYNTAX_POSIX_MINIMAL_BASIC                                   \
  421.        (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
  422.      
  423.      #define RE_SYNTAX_POSIX_EXTENDED                                        \
  424.        (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS                   \
  425.         | RE_CONTEXT_INDEP_OPS  | RE_NO_BK_BRACES                            \
  426.         | RE_NO_BK_PARENS       | RE_NO_BK_VBAR                              \
  427.         | RE_UNMATCHED_RIGHT_PAREN_ORD)
  428.      
  429.      /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
  430.         replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added.  */
  431.      #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED                                \
  432.        (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS                  \
  433.         | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES                           \
  434.         | RE_NO_BK_PARENS        | RE_NO_BK_REFS                             \
  435.         | RE_NO_BK_VBAR          | RE_UNMATCHED_RIGHT_PAREN_ORD)
  436.  
  437. 
  438. File: regex.info,  Node: Collating Elements vs. Characters,  Next: The Backslash Character,  Prev: Predefined Syntaxes,  Up: Regular Expression Syntax
  439.  
  440. Collating Elements vs. Characters
  441. =================================
  442.  
  443.   POSIX generalizes the notion of a character to that of a collating
  444. element.  It defines a "collating element" to be "a sequence of one or
  445. more bytes defined in the current collating sequence as a unit of
  446. collation."
  447.  
  448.   This generalizes the notion of a character in two ways.  First, a
  449. single character can map into two or more collating elements.  For
  450. example, the German "es-zet" collates as the collating element `s'
  451. followed by another collating element `s'.  Second, two or more
  452. characters can map into one collating element.  For example, the
  453. Spanish `ll' collates after `l' and before `m'.
  454.  
  455.   Since POSIX's "collating element" preserves the essential idea of a
  456. "character," we use the latter, more familiar, term in this document.
  457.  
  458. 
  459. File: regex.info,  Node: The Backslash Character,  Prev: Collating Elements vs. Characters,  Up: Regular Expression Syntax
  460.  
  461. The Backslash Character
  462. =======================
  463.  
  464.   The `\' character has one of four different meanings, depending on
  465. the context in which you use it and what syntax bits are set (*note
  466. Syntax Bits::.).  It can: 1) stand for itself, 2) quote the next
  467. character, 3) introduce an operator, or 4) do nothing.
  468.  
  469.   1. It stands for itself inside a list (*note List Operators::.) if
  470.      the syntax bit `RE_BACKSLASH_ESCAPE_IN_LISTS' is not set.  For
  471.      example, `[\]' would match `\'.
  472.  
  473.   2. It quotes (makes ordinary, if it's special) the next character
  474.      when you use it either:
  475.  
  476.         * outside a list,(1) or
  477.  
  478.         * inside a list and the syntax bit
  479.           `RE_BACKSLASH_ESCAPE_IN_LISTS' is set.
  480.  
  481.   3. It introduces an operator when followed by certain ordinary
  482.      characters--sometimes only when certain syntax bits are set.  See
  483.      the cases `RE_BK_PLUS_QM', `RE_NO_BK_BRACES', `RE_NO_BK_VAR',
  484.      `RE_NO_BK_PARENS', `RE_NO_BK_REF' in *Note Syntax Bits::.  Also:
  485.  
  486.         * `\b' represents the match-word-boundary operator (*note
  487.           Match-word-boundary Operator::.).
  488.  
  489.         * `\B' represents the match-within-word operator (*note
  490.           Match-within-word Operator::.).
  491.  
  492.         * `\<' represents the match-beginning-of-word operator
  493.           (*note Match-beginning-of-word Operator::.).
  494.  
  495.         * `\>' represents the match-end-of-word operator (*note
  496.           Match-end-of-word Operator::.).
  497.  
  498.         * `\w' represents the match-word-constituent operator (*note
  499.           Match-word-constituent Operator::.).
  500.  
  501.         * `\W' represents the match-non-word-constituent operator
  502.           (*note Match-non-word-constituent Operator::.).
  503.  
  504.         * `\`' represents the match-beginning-of-buffer operator and
  505.           `\'' represents the match-end-of-buffer operator (*note
  506.           Buffer Operators::.).
  507.  
  508.         * If Regex was compiled with the C preprocessor symbol `emacs'
  509.           defined, then `\sCLASS' represents the match-syntactic-class
  510.           operator and `\SCLASS' represents the
  511.           match-not-syntactic-class operator (*note Syntactic Class
  512.           Operators::.).
  513.  
  514.   4. In all other cases, Regex ignores `\'.  For example, `\n' matches
  515.      `n'.
  516.  
  517.  
  518.   ---------- Footnotes ----------
  519.  
  520.   (1)  Sometimes you don't have to explicitly quote special characters
  521. to make them ordinary.  For instance, most characters lose any special
  522. meaning inside a list (*note List Operators::.).  In addition, if the
  523. syntax bits `RE_CONTEXT_INVALID_OPS' and `RE_CONTEXT_INDEP_OPS' aren't
  524. set, then (for historical reasons) the matcher considers special
  525. characters ordinary if they are in contexts where the operations they
  526. represent make no sense; for example, then the match-zero-or-more
  527. operator (represented by `*') matches itself in the regular expression
  528. `*foo' because there is no preceding expression on which it can
  529. operate.  It is poor practice, however, to depend on this behavior; if
  530. you want a special character to be ordinary outside a list, it's better
  531. to always quote it, regardless.
  532.  
  533. 
  534. File: regex.info,  Node: Common Operators,  Next: GNU Operators,  Prev: Regular Expression Syntax,  Up: Top
  535.  
  536. Common Operators
  537. ****************
  538.  
  539.   You compose regular expressions from operators.  In the following
  540. sections, we describe the regular expression operators specified by
  541. POSIX; GNU also uses these.  Most operators have more than one
  542. representation as characters.  *Note Regular Expression Syntax::, for
  543. what characters represent what operators under what circumstances.
  544.  
  545.   For most operators that can be represented in two ways, one
  546. representation is a single character and the other is that character
  547. preceded by `\'.  For example, either `(' or `\(' represents the
  548. open-group operator.  Which one does depends on the setting of a syntax
  549. bit, in this case `RE_NO_BK_PARENS'.  Why is this so?  Historical
  550. reasons dictate some of the varying representations, while POSIX
  551. dictates others.
  552.  
  553.   Finally, almost all characters lose any special meaning inside a list
  554. (*note List Operators::.).
  555.  
  556. * Menu:
  557.  
  558. * Match-self Operator::                 Ordinary characters.
  559. * Match-any-character Operator::        .
  560. * Concatenation Operator::              Juxtaposition.
  561. * Repetition Operators::                *  +  ? {}
  562. * Alternation Operator::                |
  563. * List Operators::                      [...]  [^...]
  564. * Grouping Operators::                  (...)
  565. * Back-reference Operator::             \digit
  566. * Anchoring Operators::                 ^  $
  567.  
  568. 
  569. File: regex.info,  Node: Match-self Operator,  Next: Match-any-character Operator,  Up: Common Operators
  570.  
  571. The Match-self Operator (ORDINARY CHARACTER)
  572. ============================================
  573.  
  574.   This operator matches the character itself.  All ordinary characters
  575. (*note Regular Expression Syntax::.) represent this operator.  For
  576. example, `f' is always an ordinary character, so the regular expression
  577. `f' matches only the string `f'.  In particular, it does *not* match
  578. the string `ff'.
  579.  
  580. 
  581. File: regex.info,  Node: Match-any-character Operator,  Next: Concatenation Operator,  Prev: Match-self Operator,  Up: Common Operators
  582.  
  583. The Match-any-character Operator (`.')
  584. ======================================
  585.  
  586.   This operator matches any single printing or nonprinting character
  587. except it won't match a:
  588.  
  589. newline
  590.      if the syntax bit `RE_DOT_NEWLINE' isn't set.
  591.  
  592. null
  593.      if the syntax bit `RE_DOT_NOT_NULL' is set.
  594.  
  595.   The `.' (period) character represents this operator.  For example,
  596. `a.b' matches any three-character string beginning with `a' and ending
  597. with `b'.
  598.  
  599. 
  600. File: regex.info,  Node: Concatenation Operator,  Next: Repetition Operators,  Prev: Match-any-character Operator,  Up: Common Operators
  601.  
  602. The Concatenation Operator
  603. ==========================
  604.  
  605.   This operator concatenates two regular expressions A and B. No
  606. character represents this operator; you simply put B after A.  The
  607. result is a regular expression that will match a string if A matches
  608. its first part and B matches the rest.  For example, `xy' (two
  609. match-self operators) matches `xy'.
  610.  
  611. 
  612. File: regex.info,  Node: Repetition Operators,  Next: Alternation Operator,  Prev: Concatenation Operator,  Up: Common Operators
  613.  
  614. Repetition Operators
  615. ====================
  616.  
  617.   Repetition operators repeat the preceding regular expression a
  618. specified number of times.
  619.  
  620. * Menu:
  621.  
  622. * Match-zero-or-more Operator::  *
  623. * Match-one-or-more Operator::   +
  624. * Match-zero-or-one Operator::   ?
  625. * Interval Operators::           {}
  626.  
  627. 
  628. File: regex.info,  Node: Match-zero-or-more Operator,  Next: Match-one-or-more Operator,  Up: Repetition Operators
  629.  
  630. The Match-zero-or-more Operator (`*')
  631. -------------------------------------
  632.  
  633.   This operator repeats the smallest possible preceding regular
  634. expression as many times as necessary (including zero) to match the
  635. pattern. `*' represents this operator.  For example, `o*' matches any
  636. string made up of zero or more `o's.  Since this operator operates on
  637. the smallest preceding regular expression, `fo*' has a repeating `o',
  638. not a repeating `fo'.  So, `fo*' matches `f', `fo', `foo', and so on.
  639.  
  640.   Since the match-zero-or-more operator is a suffix operator, it may be
  641. useless as such when no regular expression precedes it.  This is the
  642. case when it:
  643.  
  644.    * is first in a regular expression, or
  645.  
  646.    * follows a match-beginning-of-line, open-group, or alternation
  647.      operator.
  648.  
  649. Three different things can happen in these cases:
  650.  
  651.   1. If the syntax bit `RE_CONTEXT_INVALID_OPS' is set, then the
  652.      regular expression is invalid.
  653.  
  654.   2. If `RE_CONTEXT_INVALID_OPS' isn't set, but `RE_CONTEXT_INDEP_OPS'
  655.      is, then `*' represents the match-zero-or-more operator (which
  656.      then operates on the empty string).
  657.  
  658.   3. Otherwise, `*' is ordinary.
  659.  
  660.  
  661.   The matcher processes a match-zero-or-more operator by first matching
  662. as many repetitions of the smallest preceding regular expression as it
  663. can. Then it continues to match the rest of the pattern.
  664.  
  665.   If it can't match the rest of the pattern, it backtracks (as many
  666. times as necessary), each time discarding one of the matches until it
  667. can either match the entire pattern or be certain that it cannot get a
  668. match.  For example, when matching `ca*ar' against `caaar', the matcher
  669. first matches all three `a's of the string with the `a*' of the regular
  670. expression.  However, it cannot then match the final `ar' of the
  671. regular expression against the final `r' of the string.  So it
  672. backtracks, discarding the match of the last `a' in the string.  It can
  673. then match the remaining `ar'.
  674.  
  675. 
  676. File: regex.info,  Node: Match-one-or-more Operator,  Next: Match-zero-or-one Operator,  Prev: Match-zero-or-more Operator,  Up: Repetition Operators
  677.  
  678. The Match-one-or-more Operator (`+' or `\+')
  679. --------------------------------------------
  680.  
  681.   If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't
  682. recognize this operator.  Otherwise, if the syntax bit `RE_BK_PLUS_QM'
  683. isn't set, then `+' represents this operator; if it is, then `\+' does.
  684.  
  685.   This operator is similar to the match-zero-or-more operator except
  686. that it repeats the preceding regular expression at least once; *note
  687. Match-zero-or-more Operator::., for what it operates on, how some
  688. syntax bits affect it, and how Regex backtracks to match it.
  689.  
  690.   For example, supposing that `+' represents the match-one-or-more
  691. operator; then `ca+r' matches, e.g., `car' and `caaaar', but not `cr'.
  692.  
  693. 
  694. File: regex.info,  Node: Match-zero-or-one Operator,  Next: Interval Operators,  Prev: Match-one-or-more Operator,  Up: Repetition Operators
  695.  
  696. The Match-zero-or-one Operator (`?' or `\?')
  697. --------------------------------------------
  698.  
  699.   If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't
  700. recognize this operator.  Otherwise, if the syntax bit `RE_BK_PLUS_QM'
  701. isn't set, then `?' represents this operator; if it is, then `\?' does.
  702.  
  703.   This operator is similar to the match-zero-or-more operator except
  704. that it repeats the preceding regular expression once or not at all;
  705. *note Match-zero-or-more Operator::., to see what it operates on, how
  706. some syntax bits affect it, and how Regex backtracks to match it.
  707.  
  708.   For example, supposing that `?' represents the match-zero-or-one
  709. operator; then `ca?r' matches both `car' and `cr', but nothing else.
  710.  
  711. 
  712. File: regex.info,  Node: Interval Operators,  Prev: Match-zero-or-one Operator,  Up: Repetition Operators
  713.  
  714. Interval Operators (`{' ... `}' or `\{' ... `\}')
  715. -------------------------------------------------
  716.  
  717.   If the syntax bit `RE_INTERVALS' is set, then Regex recognizes
  718. "interval expressions".  They repeat the smallest possible preceding
  719. regular expression a specified number of times.
  720.  
  721.   If the syntax bit `RE_NO_BK_BRACES' is set, `{' represents the
  722. "open-interval operator" and `}' represents the "close-interval
  723. operator" ; otherwise, `\{' and `\}' do.
  724.  
  725.   Specifically, supposing that `{' and `}' represent the open-interval
  726. and close-interval operators; then:
  727.  
  728. `{COUNT}'
  729.      matches exactly COUNT occurrences of the preceding regular
  730.      expression.
  731.  
  732. `{MIN,}'
  733.      matches MIN or more occurrences of the preceding regular
  734.      expression.
  735.  
  736. `{MIN, MAX}'
  737.      matches at least MIN but no more than MAX occurrences of the
  738.      preceding regular expression.
  739.  
  740.   The interval expression (but not necessarily the regular expression
  741. that contains it) is invalid if:
  742.  
  743.    * MIN is greater than MAX, or
  744.  
  745.    * any of COUNT, MIN, or MAX are outside the range zero to
  746.      `RE_DUP_MAX' (which symbol `regex.h' defines).
  747.  
  748.   If the interval expression is invalid and the syntax bit
  749. `RE_NO_BK_BRACES' is set, then Regex considers all the characters in
  750. the would-be interval to be ordinary.  If that bit isn't set, then the
  751. regular expression is invalid.
  752.  
  753.   If the interval expression is valid but there is no preceding regular
  754. expression on which to operate, then if the syntax bit
  755. `RE_CONTEXT_INVALID_OPS' is set, the regular expression is invalid. If
  756. that bit isn't set, then Regex considers all the characters--other than
  757. backslashes, which it ignores--in the would-be interval to be ordinary.
  758.  
  759. 
  760. File: regex.info,  Node: Alternation Operator,  Next: List Operators,  Prev: Repetition Operators,  Up: Common Operators
  761.  
  762. The Alternation Operator (`|' or `\|')
  763. ======================================
  764.  
  765.   If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't
  766. recognize this operator.  Otherwise, if the syntax bit `RE_NO_BK_VBAR'
  767. is set, then `|' represents this operator; otherwise, `\|' does.
  768.  
  769.   Alternatives match one of a choice of regular expressions: if you put
  770. the character(s) representing the alternation operator between any two
  771. regular expressions A and B, the result matches the union of the
  772. strings that A and B match.  For example, supposing that `|' is the
  773. alternation operator, then `foo|bar|quux' would match any of `foo',
  774. `bar' or `quux'.
  775.  
  776.   The alternation operator operates on the *largest* possible
  777. surrounding regular expressions.  (Put another way, it has the lowest
  778. precedence of any regular expression operator.) Thus, the only way you
  779. can delimit its arguments is to use grouping.  For example, if `(' and
  780. `)' are the open and close-group operators, then `fo(o|b)ar' would
  781. match either `fooar' or `fobar'.  (`foo|bar' would match `foo' or
  782. `bar'.)
  783.  
  784.   The matcher tries all combinations of alternatives so as to match the
  785. longest possible string.  For example, when matching
  786. `(fooq|foo)*(qbarquux|bar)' against `fooqbarquux', it cannot take, say,
  787. the first ("depth-first") combination it could match, since then it
  788. would be content to match just `fooqbar'.
  789.  
  790. 
  791. File: regex.info,  Node: List Operators,  Next: Grouping Operators,  Prev: Alternation Operator,  Up: Common Operators
  792.  
  793. List Operators (`[' ... `]' and `[^' ... `]')
  794. =============================================
  795.  
  796.   "Lists", also called "bracket expressions", are a set of one or more
  797. items.  An "item" is a character, a character class expression, or a
  798. range expression.  The syntax bits affect which kinds of items you can
  799. put in a list.  We explain the last two items in subsections below. 
  800. Empty lists are invalid.
  801.  
  802.   A "matching list" matches a single character represented by one of
  803. the list items.  You form a matching list by enclosing one or more items
  804. within an "open-matching-list operator" (represented by `[') and a
  805. "close-list operator" (represented by `]').
  806.  
  807.   For example, `[ab]' matches either `a' or `b'. `[ad]*' matches the
  808. empty string and any string composed of just `a's and `d's in any
  809. order.  Regex considers invalid a regular expression with a `[' but no
  810. matching `]'.
  811.  
  812.   "Nonmatching lists" are similar to matching lists except that they
  813. match a single character *not* represented by one of the list items. 
  814. You use an "open-nonmatching-list operator" (represented by `[^'(1))
  815. instead of an open-matching-list operator to start a nonmatching list.
  816.  
  817.   For example, `[^ab]' matches any character except `a' or `b'.
  818.  
  819.   If the `posix_newline' field in the pattern buffer (*note GNU Pattern
  820. Buffers::. is set, then nonmatching lists do not match a newline.
  821.  
  822.   Most characters lose any special meaning inside a list.  The special
  823. characters inside a list follow.
  824.  
  825. `]'
  826.      ends the list if it's not the first list item.  So, if you want to
  827.      make the `]' character a list item, you must put it first.
  828.  
  829. `\'
  830.      quotes the next character if the syntax bit
  831.      `RE_BACKSLASH_ESCAPE_IN_LISTS' is set.
  832.  
  833. `[:'
  834.      represents the open-character-class operator (*note Character
  835.      Class Operators::.) if the syntax bit `RE_CHAR_CLASSES' is set and
  836.      what follows is a valid character class expression.
  837.  
  838. `:]'
  839.      represents the close-character-class operator if the syntax bit
  840.      `RE_CHAR_CLASSES' is set and what precedes it is an
  841.      open-character-class operator followed by a valid character class
  842.      name.
  843.  
  844. `-'
  845.      represents the range operator (*note Range Operator::.) if it's
  846.      not first or last in a list or the ending point of a range.
  847.  
  848. All other characters are ordinary.  For example, `[.*]' matches `.' and
  849. `*'.
  850.  
  851. * Menu:
  852.  
  853. * Character Class Operators::   [:class:]
  854. * Range Operator::          start-end
  855.  
  856.   ---------- Footnotes ----------
  857.  
  858.   (1)  Regex therefore doesn't consider the `^' to be the first
  859. character in the list.  If you put a `^' character first in (what you
  860. think is) a matching list, you'll turn it into a nonmatching list.
  861.  
  862. 
  863. File: regex.info,  Node: Character Class Operators,  Next: Range Operator,  Up: List Operators
  864.  
  865. Character Class Operators (`[:' ... `:]')
  866. -----------------------------------------
  867.  
  868.   If the syntax bit `RE_CHARACTER_CLASSES' is set, then Regex
  869. recognizes character class expressions inside lists.  A "character
  870. class expression" matches one character from a given class.  You form a
  871. character class expression by putting a character class name between an
  872. "open-character-class operator" (represented by `[:') and a
  873. "close-character-class operator" (represented by `:]').  The character
  874. class names and their meanings are:
  875.  
  876. `alnum'
  877.      letters and digits
  878.  
  879. `alpha'
  880.      letters
  881.  
  882. `blank'
  883.      system-dependent; for GNU, a space or tab
  884.  
  885. `cntrl'
  886.      control characters (in the ASCII encoding, code 0177 and codes
  887.      less than 040)
  888.  
  889. `digit'
  890.      digits
  891.  
  892. `graph'
  893.      same as `print' except omits space
  894.  
  895. `lower'
  896.      lowercase letters
  897.  
  898. `print'
  899.      printable characters (in the ASCII encoding, space tilde--codes
  900.      040 through 0176)
  901.  
  902. `punct'
  903.      neither control nor alphanumeric characters
  904.  
  905. `space'
  906.      space, carriage return, newline, vertical tab, and form feed
  907.  
  908. `upper'
  909.      uppercase letters
  910.  
  911. `xdigit'
  912.      hexadecimal digits: `0'--`9', `a'--`f', `A'--`F'
  913.  
  914. These correspond to the definitions in the C library's `<ctype.h>'
  915. facility.  For example, `[:alpha:]' corresponds to the standard
  916. facility `isalpha'.  Regex recognizes character class expressions only
  917. inside of lists; so `[[:alpha:]]' matches any letter, but `[:alpha:]'
  918. outside of a bracket expression and not followed by a repetition
  919. operator matches just itself.
  920.  
  921. 
  922. File: regex.info,  Node: Range Operator,  Prev: Character Class Operators,  Up: List Operators
  923.  
  924. The Range Operator (`-')
  925. ------------------------
  926.  
  927.   Regex recognizes "range expressions" inside a list. They represent
  928. those characters that fall between two elements in the current
  929. collating sequence.  You form a range expression by putting a "range
  930. operator" between two characters.(1) `-' represents the range operator.
  931.  For example, `a-f' within a list represents all the characters from `a'
  932. through `f' inclusively.
  933.  
  934.   If the syntax bit `RE_NO_EMPTY_RANGES' is set, then if the range's
  935. ending point collates less than its starting point, the range (and the
  936. regular expression containing it) is invalid.  For example, the regular
  937. expression `[z-a]' would be invalid.  If this bit isn't set, then Regex
  938. considers such a range to be empty.
  939.  
  940.   Since `-' represents the range operator, if you want to make a `-'
  941. character itself a list item, you must do one of the following:
  942.  
  943.    * Put the `-' either first or last in the list.
  944.  
  945.    * Include a range whose starting point collates strictly lower than
  946.      `-' and whose ending point collates equal or higher.  Unless a
  947.      range is the first item in a list, a `-' can't be its starting
  948.      point, but *can* be its ending point.  That is because Regex
  949.      considers `-' to be the range operator unless it is preceded by
  950.      another `-'.  For example, in the ASCII encoding, `)', `*', `+',
  951.      `,', `-', `.', and `/' are contiguous characters in the collating
  952.      sequence.  You might think that `[)-+--/]' has two ranges: `)-+'
  953.      and `--/'.  Rather, it has the ranges `)-+' and `+--', plus the
  954.      character `/', so it matches, e.g., `,', not `.'.
  955.  
  956.    * Put a range whose starting point is `-' first in the list.
  957.  
  958.   For example, `[-a-z]' matches a lowercase letter or a hyphen (in
  959. English, in ASCII).
  960.  
  961.   ---------- Footnotes ----------
  962.  
  963.   (1)  You can't use a character class for the starting or ending point
  964. of a range, since a character class is not a single character.
  965.  
  966. 
  967. File: regex.info,  Node: Grouping Operators,  Next: Back-reference Operator,  Prev: List Operators,  Up: Common Operators
  968.  
  969. Grouping Operators (`(' ... `)' or `\(' ... `\)')
  970. =================================================
  971.  
  972.   A "group", also known as a "subexpression", consists of an
  973. "open-group operator", any number of other operators, and a
  974. "close-group operator".  Regex treats this sequence as a unit, just as
  975. mathematics and programming languages treat a parenthesized expression
  976. as a unit.
  977.  
  978.   Therefore, using "groups", you can:
  979.  
  980.    * delimit the argument(s) to an alternation operator (*note
  981.      Alternation Operator::.) or a repetition operator (*note
  982.      Repetition Operators::.).
  983.  
  984.    * keep track of the indices of the substring that matched a given
  985.      group. *Note Using Registers::, for a precise explanation. This
  986.      lets you:
  987.  
  988.         * use the back-reference operator (*note Back-reference
  989.           Operator::.).
  990.  
  991.         * use registers (*note Using Registers::.).
  992.  
  993.   If the syntax bit `RE_NO_BK_PARENS' is set, then `(' represents the
  994. open-group operator and `)' represents the close-group operator;
  995. otherwise, `\(' and `\)' do.
  996.  
  997.   If the syntax bit `RE_UNMATCHED_RIGHT_PAREN_ORD' is set and a
  998. close-group operator has no matching open-group operator, then Regex
  999. considers it to match `)'.
  1000.  
  1001. 
  1002. File: regex.info,  Node: Back-reference Operator,  Next: Anchoring Operators,  Prev: Grouping Operators,  Up: Common Operators
  1003.  
  1004. The Back-reference Operator ("\"DIGIT)
  1005. ======================================
  1006.  
  1007.   If the syntax bit `RE_NO_BK_REF' isn't set, then Regex recognizes
  1008. back references.  A back reference matches a specified preceding group.
  1009. The back reference operator is represented by `\DIGIT' anywhere after
  1010. the end of a regular expression's DIGIT-th group (*note Grouping
  1011. Operators::.).
  1012.  
  1013.   DIGIT must be between `1' and `9'.  The matcher assigns numbers 1
  1014. through 9 to the first nine groups it encounters.  By using one of `\1'
  1015. through `\9' after the corresponding group's close-group operator, you
  1016. can match a substring identical to the one that the group does.
  1017.  
  1018.   Back references match according to the following (in all examples
  1019. below, `(' represents the open-group, `)' the close-group, `{' the
  1020. open-interval and `}' the close-interval operator):
  1021.  
  1022.    * If the group matches a substring, the back reference matches an
  1023.      identical substring.  For example, `(a)\1' matches `aa' and
  1024.      `(bana)na\1bo\1' matches `bananabanabobana'.  Likewise, `(.*)\1'
  1025.      matches any (newline-free if the syntax bit `RE_DOT_NEWLINE' isn't
  1026.      set) string that is composed of two identical halves; the `(.*)'
  1027.      matches the first half and the `\1' matches the second half.
  1028.  
  1029.    * If the group matches more than once (as it might if followed by,
  1030.      e.g., a repetition operator), then the back reference matches the
  1031.      substring the group *last* matched.  For example, `((a*)b)*\1\2'
  1032.      matches `aabababa'; first group 1 (the outer one) matches `aab'
  1033.      and group 2 (the inner one) matches `aa'.  Then group 1 matches
  1034.      `ab' and group 2 matches `a'.  So, `\1' matches `ab' and `\2'
  1035.      matches `a'.
  1036.  
  1037.    * If the group doesn't participate in a match, i.e., it is part of an
  1038.      alternative not taken or a repetition operator allows zero
  1039.      repetitions of it, then the back reference makes the whole match
  1040.      fail.  For example, `(one()|two())-and-(three\2|four\3)' matches
  1041.      `one-and-three' and `two-and-four', but not `one-and-four' or
  1042.      `two-and-three'.  For example, if the pattern matches `one-and-',
  1043.      then its group 2 matches the empty string and its group 3 doesn't
  1044.      participate in the match.  So, if it then matches `four', then
  1045.      when it tries to back reference group 3--which it will attempt to
  1046.      do because `\3' follows the `four'--the match will fail because
  1047.      group 3 didn't participate in the match.
  1048.  
  1049.   You can use a back reference as an argument to a repetition operator.
  1050.  For example, `(a(b))\2*' matches `a' followed by two or more `b's. 
  1051. Similarly, `(a(b))\2{3}' matches `abbbb'.
  1052.  
  1053.   If there is no preceding DIGIT-th subexpression, the regular
  1054. expression is invalid.
  1055.  
  1056. 
  1057. File: regex.info,  Node: Anchoring Operators,  Prev: Back-reference Operator,  Up: Common Operators
  1058.  
  1059. Anchoring Operators
  1060. ===================
  1061.  
  1062.   These operators can constrain a pattern to match only at the
  1063. beginning or end of the entire string or at the beginning or end of a
  1064. line.
  1065.  
  1066. * Menu:
  1067.  
  1068. * Match-beginning-of-line Operator::  ^
  1069. * Match-end-of-line Operator::        $
  1070.  
  1071. 
  1072. File: regex.info,  Node: Match-beginning-of-line Operator,  Next: Match-end-of-line Operator,  Up: Anchoring Operators
  1073.  
  1074. The Match-beginning-of-line Operator (`^')
  1075. ------------------------------------------
  1076.  
  1077.   This operator can match the empty string either at the beginning of
  1078. the string or after a newline character.  Thus, it is said to "anchor"
  1079. the pattern to the beginning of a line.
  1080.  
  1081.   In the cases following, `^' represents this operator.  (Otherwise,
  1082. `^' is ordinary.)
  1083.  
  1084.    * It (the `^') is first in the pattern, as in `^foo'.
  1085.  
  1086.    * The syntax bit `RE_CONTEXT_INDEP_ANCHORS' is set, and it is outside
  1087.      a bracket expression.
  1088.  
  1089.    * It follows an open-group or alternation operator, as in `a\(^b\)'
  1090.      and `a\|^b'.  *Note Grouping Operators::, and *Note Alternation
  1091.      Operator::.
  1092.  
  1093.   These rules imply that some valid patterns containing `^' cannot be
  1094. matched; for example, `foo^bar' if `RE_CONTEXT_INDEP_ANCHORS' is set.
  1095.  
  1096.   If the `not_bol' field is set in the pattern buffer (*note GNU
  1097. Pattern Buffers::.), then `^' fails to match at the beginning of the
  1098. string.  *Note POSIX Matching::, for when you might find this useful.
  1099.  
  1100.   If the `newline_anchor' field is set in the pattern buffer, then `^'
  1101. fails to match after a newline.  This is useful when you do not regard
  1102. the string to be matched as broken into lines.
  1103.  
  1104. 
  1105. File: regex.info,  Node: Match-end-of-line Operator,  Prev: Match-beginning-of-line Operator,  Up: Anchoring Operators
  1106.  
  1107. The Match-end-of-line Operator (`$')
  1108. ------------------------------------
  1109.  
  1110.   This operator can match the empty string either at the end of the
  1111. string or before a newline character in the string.  Thus, it is said
  1112. to "anchor" the pattern to the end of a line.
  1113.  
  1114.   It is always represented by `$'.  For example, `foo$' usually
  1115. matches, e.g., `foo' and, e.g., the first three characters of
  1116. `foo\nbar'.
  1117.  
  1118.   Its interaction with the syntax bits and pattern buffer fields is
  1119. exactly the dual of `^''s; see the previous section.  (That is,
  1120. "beginning" becomes "end", "next" becomes "previous", and "after"
  1121. becomes "before".)
  1122.  
  1123. 
  1124. File: regex.info,  Node: GNU Operators,  Next: GNU Emacs Operators,  Prev: Common Operators,  Up: Top
  1125.  
  1126. GNU Operators
  1127. *************
  1128.  
  1129.   Following are operators that GNU defines (and POSIX doesn't).
  1130.  
  1131. * Menu:
  1132.  
  1133. * Word Operators::
  1134. * Buffer Operators::
  1135.  
  1136. 
  1137. File: regex.info,  Node: Word Operators,  Next: Buffer Operators,  Up: GNU Operators
  1138.  
  1139. Word Operators
  1140. ==============
  1141.  
  1142.   The operators in this section require Regex to recognize parts of
  1143. words. Regex uses a syntax table to determine whether or not a
  1144. character is part of a word, i.e., whether or not it is
  1145. "word-constituent".
  1146.  
  1147. * Menu:
  1148.  
  1149. * Non-Emacs Syntax Tables::
  1150. * Match-word-boundary Operator::        \b
  1151. * Match-within-word Operator::          \B
  1152. * Match-beginning-of-word Operator::    \<
  1153. * Match-end-of-word Operator::          \>
  1154. * Match-word-constituent Operator::     \w
  1155. * Match-non-word-constituent Operator:: \W
  1156.  
  1157. 
  1158. File: regex.info,  Node: Non-Emacs Syntax Tables,  Next: Match-word-boundary Operator,  Up: Word Operators
  1159.  
  1160. Non-Emacs Syntax Tables
  1161. -----------------------
  1162.  
  1163.   A "syntax table" is an array indexed by the characters in your
  1164. character set.  In the ASCII encoding, therefore, a syntax table has
  1165. 256 elements.  Regex always uses a `char *' variable `re_syntax_table'
  1166. as its syntax table.  In some cases, it initializes this variable and
  1167. in others it expects you to initialize it.
  1168.  
  1169.    * If Regex is compiled with the preprocessor symbols `emacs' and
  1170.      `SYNTAX_TABLE' both undefined, then Regex allocates
  1171.      `re_syntax_table' and initializes an element I either to `Sword'
  1172.      (which it defines) if I is a letter, number, or `_', or to zero if
  1173.      it's not.
  1174.  
  1175.    * If Regex is compiled with `emacs' undefined but `SYNTAX_TABLE'
  1176.      defined, then Regex expects you to define a `char *' variable
  1177.      `re_syntax_table' to be a valid syntax table.
  1178.  
  1179.    * *Note Emacs Syntax Tables::, for what happens when Regex is
  1180.      compiled with the preprocessor symbol `emacs' defined.
  1181.  
  1182. 
  1183. File: regex.info,  Node: Match-word-boundary Operator,  Next: Match-within-word Operator,  Prev: Non-Emacs Syntax Tables,  Up: Word Operators
  1184.  
  1185. The Match-word-boundary Operator (`\b')
  1186. ---------------------------------------
  1187.  
  1188.   This operator (represented by `\b') matches the empty string at
  1189. either the beginning or the end of a word.  For example, `\brat\b'
  1190. matches the separate word `rat'.
  1191.  
  1192. 
  1193. File: regex.info,  Node: Match-within-word Operator,  Next: Match-beginning-of-word Operator,  Prev: Match-word-boundary Operator,  Up: Word Operators
  1194.  
  1195. The Match-within-word Operator (`\B')
  1196. -------------------------------------
  1197.  
  1198.   This operator (represented by `\B') matches the empty string within a
  1199. word. For example, `c\Brat\Be' matches `crate', but `dirty \Brat'
  1200. doesn't match `dirty rat'.
  1201.  
  1202. 
  1203. File: regex.info,  Node: Match-beginning-of-word Operator,  Next: Match-end-of-word Operator,  Prev: Match-within-word Operator,  Up: Word Operators
  1204.  
  1205. The Match-beginning-of-word Operator (`\<')
  1206. -------------------------------------------
  1207.  
  1208.   This operator (represented by `\<') matches the empty string at the
  1209. beginning of a word.
  1210.  
  1211. 
  1212. File: regex.info,  Node: Match-end-of-word Operator,  Next: Match-word-constituent Operator,  Prev: Match-beginning-of-word Operator,  Up: Word Operators
  1213.  
  1214. The Match-end-of-word Operator (`\>')
  1215. -------------------------------------
  1216.  
  1217.   This operator (represented by `\>') matches the empty string at the
  1218. end of a word.
  1219.  
  1220. 
  1221. File: regex.info,  Node: Match-word-constituent Operator,  Next: Match-non-word-constituent Operator,  Prev: Match-end-of-word Operator,  Up: Word Operators
  1222.  
  1223. The Match-word-constituent Operator (`\w')
  1224. ------------------------------------------
  1225.  
  1226.   This operator (represented by `\w') matches any word-constituent
  1227. character.
  1228.  
  1229. 
  1230. File: regex.info,  Node: Match-non-word-constituent Operator,  Prev: Match-word-constituent Operator,  Up: Word Operators
  1231.  
  1232. The Match-non-word-constituent Operator (`\W')
  1233. ----------------------------------------------
  1234.  
  1235.   This operator (represented by `\W') matches any character that is not
  1236. word-constituent.
  1237.  
  1238. 
  1239. File: regex.info,  Node: Buffer Operators,  Prev: Word Operators,  Up: GNU Operators
  1240.  
  1241. Buffer Operators
  1242. ================
  1243.  
  1244.   Following are operators which work on buffers.  In Emacs, a "buffer"
  1245. is, naturally, an Emacs buffer.  For other programs, Regex considers the
  1246. entire string to be matched as the buffer.
  1247.  
  1248. * Menu:
  1249.  
  1250. * Match-beginning-of-buffer Operator::  \`
  1251. * Match-end-of-buffer Operator::        \'
  1252.  
  1253. 
  1254. File: regex.info,  Node: Match-beginning-of-buffer Operator,  Next: Match-end-of-buffer Operator,  Up: Buffer Operators
  1255.  
  1256. The Match-beginning-of-buffer Operator (`\`')
  1257. ---------------------------------------------
  1258.  
  1259.   This operator (represented by `\`') matches the empty string at the
  1260. beginning of the buffer.
  1261.  
  1262. 
  1263. File: regex.info,  Node: Match-end-of-buffer Operator,  Prev: Match-beginning-of-buffer Operator,  Up: Buffer Operators
  1264.  
  1265. The Match-end-of-buffer Operator (`\'')
  1266. ---------------------------------------
  1267.  
  1268.   This operator (represented by `\'') matches the empty string at the
  1269. end of the buffer.
  1270.  
  1271. 
  1272. File: regex.info,  Node: GNU Emacs Operators,  Next: What Gets Matched?,  Prev: GNU Operators,  Up: Top
  1273.  
  1274. GNU Emacs Operators
  1275. *******************
  1276.  
  1277.   Following are operators that GNU defines (and POSIX doesn't) that you
  1278. can use only when Regex is compiled with the preprocessor symbol
  1279. `emacs' defined.
  1280.  
  1281. * Menu:
  1282.  
  1283. * Syntactic Class Operators::
  1284.  
  1285. 
  1286. File: regex.info,  Node: Syntactic Class Operators,  Up: GNU Emacs Operators
  1287.  
  1288. Syntactic Class Operators
  1289. =========================
  1290.  
  1291.   The operators in this section require Regex to recognize the syntactic
  1292. classes of characters.  Regex uses a syntax table to determine this.
  1293.  
  1294. * Menu:
  1295.  
  1296. * Emacs Syntax Tables::
  1297. * Match-syntactic-class Operator::      \sCLASS
  1298. * Match-not-syntactic-class Operator::  \SCLASS
  1299.  
  1300. 
  1301. File: regex.info,  Node: Emacs Syntax Tables,  Next: Match-syntactic-class Operator,  Up: Syntactic Class Operators
  1302.  
  1303. Emacs Syntax Tables
  1304. -------------------
  1305.  
  1306.   A "syntax table" is an array indexed by the characters in your
  1307. character set.  In the ASCII encoding, therefore, a syntax table has
  1308. 256 elements.
  1309.  
  1310.   If Regex is compiled with the preprocessor symbol `emacs' defined,
  1311. then Regex expects you to define and initialize the variable
  1312. `re_syntax_table' to be an Emacs syntax table.  Emacs' syntax tables
  1313. are more complicated than Regex's own (*note Non-Emacs Syntax
  1314. Tables::.).  *Note Syntax: (emacs)Syntax, for a description of Emacs'
  1315. syntax tables.
  1316.  
  1317. 
  1318. File: regex.info,  Node: Match-syntactic-class Operator,  Next: Match-not-syntactic-class Operator,  Prev: Emacs Syntax Tables,  Up: Syntactic Class Operators
  1319.  
  1320. The Match-syntactic-class Operator (`\s'CLASS)
  1321. ----------------------------------------------
  1322.  
  1323.   This operator matches any character whose syntactic class is
  1324. represented by a specified character.  `\sCLASS' represents this
  1325. operator where CLASS is the character representing the syntactic class
  1326. you want.  For example, `w' represents the syntactic class of
  1327. word-constituent characters, so `\sw' matches any word-constituent
  1328. character.
  1329.  
  1330. 
  1331. File: regex.info,  Node: Match-not-syntactic-class Operator,  Prev: Match-syntactic-class Operator,  Up: Syntactic Class Operators
  1332.  
  1333. The Match-not-syntactic-class Operator (`\S'CLASS)
  1334. --------------------------------------------------
  1335.  
  1336.   This operator is similar to the match-syntactic-class operator except
  1337. that it matches any character whose syntactic class is *not*
  1338. represented by the specified character.  `\SCLASS' represents this
  1339. operator.  For example, `w' represents the syntactic class of
  1340. word-constituent characters, so `\Sw' matches any character that is not
  1341. word-constituent.
  1342.  
  1343. 
  1344. File: regex.info,  Node: What Gets Matched?,  Next: Programming with Regex,  Prev: GNU Emacs Operators,  Up: Top
  1345.  
  1346. What Gets Matched?
  1347. ******************
  1348.  
  1349.   Regex matches strings according to the "leftmost longest" rule; that
  1350. is, it chooses the longest of the leftmost matches.  This does not mean
  1351. that for a regular expression containing subexpressions that it simply
  1352. chooses the longest match for each subexpression, left to right; the
  1353. overall match must also be the longest possible one.
  1354.  
  1355.   For example, `(ac*)(c*d[ac]*)\1' matches `acdacaaa', not `acdac', as
  1356. it would if it were to choose the longest match for the first
  1357. subexpression.
  1358.  
  1359. 
  1360. File: regex.info,  Node: Programming with Regex,  Next: Copying,  Prev: What Gets Matched?,  Up: Top
  1361.  
  1362. Programming with Regex
  1363. **********************
  1364.  
  1365.   Here we describe how you use the Regex data structures and functions
  1366. in C programs.  Regex has three interfaces: one designed for GNU, one
  1367. compatible with POSIX and one compatible with Berkeley UNIX.
  1368.  
  1369. * Menu:
  1370.  
  1371. * GNU Regex Functions::
  1372. * POSIX Regex Functions::
  1373. * BSD Regex Functions::
  1374.  
  1375. 
  1376. File: regex.info,  Node: GNU Regex Functions,  Next: POSIX Regex Functions,  Up: Programming with Regex
  1377.  
  1378. GNU Regex Functions
  1379. ===================
  1380.  
  1381.   If you're writing code that doesn't need to be compatible with either
  1382. POSIX or Berkeley UNIX, you can use these functions.  They provide more
  1383. options than the other interfaces.
  1384.  
  1385. * Menu:
  1386.  
  1387. * GNU Pattern Buffers::         The re_pattern_buffer type.
  1388. * GNU Regular Expression Compiling::  re_compile_pattern ()
  1389. * GNU Matching::                re_match ()
  1390. * GNU Searching::               re_search ()
  1391. * Matching/Searching with Split Data::  re_match_2 (), re_search_2 ()
  1392. * Searching with Fastmaps::     re_compile_fastmap ()
  1393. * GNU Translate Tables::        The `translate' field.
  1394. * Using Registers::             The re_registers type and related fns.
  1395. * Freeing GNU Pattern Buffers::  regfree ()
  1396.  
  1397. 
  1398. File: regex.info,  Node: GNU Pattern Buffers,  Next: GNU Regular Expression Compiling,  Up: GNU Regex Functions
  1399.  
  1400. GNU Pattern Buffers
  1401. -------------------
  1402.  
  1403.   To compile, match, or search for a given regular expression, you must
  1404. supply a pattern buffer.  A "pattern buffer" holds one compiled regular
  1405. expression.(1)  You can have several different pattern buffers
  1406. simultaneously, each holding a compiled pattern for a different regular
  1407. expression.  A pattern buffer is a structure `struct re_pattern_buffer'
  1408. defined in `regex.h' as follows:
  1409.  
  1410.              /* Space that holds the compiled pattern.  It is declared as
  1411.                `unsigned char *' because its elements are
  1412.                 sometimes used as array indexes.  */
  1413.        unsigned char *buffer;
  1414.      
  1415.              /* Number of bytes to which `buffer' points.  */
  1416.        unsigned long allocated;
  1417.      
  1418.              /* Number of bytes actually used in `buffer'.  */
  1419.        unsigned long used;
  1420.      
  1421.              /* Syntax setting with which the pattern was compiled.  */
  1422.        reg_syntax_t syntax;
  1423.      
  1424.              /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
  1425.                 the fastmap, if there is one, to skip over impossible
  1426.                 starting points for matches.  */
  1427.        char *fastmap;
  1428.      
  1429.              /* Either a translate table to apply to all characters before
  1430.                 comparing them, or zero for no translation.  The translation
  1431.                 is applied to a pattern when it is compiled and to a string
  1432.                 when it is matched.  */
  1433.        char *translate;
  1434.      
  1435.              /* Number of subexpressions found by the compiler.  */
  1436.        size_t re_nsub;
  1437.      
  1438.              /* Zero if this pattern cannot match the empty string, one else.
  1439.                 Well, in truth it's used only in `re_search_2', to see
  1440.                 whether or not we should use the fastmap, so we don't set
  1441.                 this absolutely perfectly; see `re_compile_fastmap' (the
  1442.                 `duplicate' case).  */
  1443.        unsigned can_be_null : 1;
  1444.      
  1445.              /* If REGS_UNALLOCATED, allocate space in the `regs' structure
  1446.                   for `max (RE_NREGS, re_nsub + 1)' groups.
  1447.                 If REGS_REALLOCATE, reallocate space if necessary.
  1448.                 If REGS_FIXED, use what's there.  */
  1449.      #define REGS_UNALLOCATED 0
  1450.      #define REGS_REALLOCATE 1
  1451.      #define REGS_FIXED 2
  1452.        unsigned regs_allocated : 2;
  1453.      
  1454.              /* Set to zero when regex_compile compiles a pattern; set to one
  1455.                 by re_compile_fastmap when it updates the fastmap, if any.  */
  1456.        unsigned fastmap_accurate : 1;
  1457.      
  1458.              /* If set, regexec reports only success or failure and does not
  1459.                 return anything in pmatch.  */
  1460.        unsigned no_sub : 1;
  1461.      
  1462.              /* If set, a beginning-of-line anchor doesn't match at the
  1463.                 beginning of the string.  */
  1464.        unsigned not_bol : 1;
  1465.      
  1466.              /* Similarly for an end-of-line anchor.  */
  1467.        unsigned not_eol : 1;
  1468.      
  1469.              /* If true, an anchor at a newline matches.  */
  1470.        unsigned newline_anchor : 1;
  1471.  
  1472.   ---------- Footnotes ----------
  1473.  
  1474.   (1)  Regular expressions are also referred to as "patterns," hence
  1475. the name "pattern buffer."
  1476.  
  1477. 
  1478. File: regex.info,  Node: GNU Regular Expression Compiling,  Next: GNU Matching,  Prev: GNU Pattern Buffers,  Up: GNU Regex Functions
  1479.  
  1480. GNU Regular Expression Compiling
  1481. --------------------------------
  1482.  
  1483.   In GNU, you can both match and search for a given regular expression.
  1484.  To do either, you must first compile it in a pattern buffer (*note GNU
  1485. Pattern Buffers::.).  Regular expressions match according to the syntax
  1486. with which they were compiled; with GNU, you indicate what syntax you
  1487. want by setting the variable `re_syntax_options' (declared in `regex.h'
  1488. and defined in `regex.c') before calling the compiling function,
  1489. `re_compile_pattern' (see below). *Note Syntax Bits::, and *Note
  1490. Predefined Syntaxes::.
  1491.  
  1492.   Your program can change the value of `re_syntax_options' at any time.
  1493. Usually, however, you set its value once and then never change it.
  1494.  
  1495.   `re_compile_pattern' takes a pattern buffer as an argument.  You must
  1496. initialize the following fields:
  1497.  
  1498. `translate'
  1499.      either to point to a translate table if you want one, or to zero
  1500.      if you don't.  We explain translate tables in *Note GNU Translate
  1501.      Tables::.
  1502.  
  1503. `fastmap'
  1504.      to nonzero if you want a fastmap, and to zero if you don't.
  1505.  
  1506. `buffer'
  1507.      (which is where `re_compile_pattern' puts the compiled pattern) in
  1508.      one of two ways:
  1509.  
  1510.        1. Set its `buffer' field to the address of a block of memory
  1511.           obtained with the C library facility `malloc' and the
  1512.           `allocated' field to the size (in bytes) of the block.  You
  1513.           might do this if you already have storage allocated that you
  1514.           want to use.
  1515.  
  1516.        2. Set its `allocated' and `buffer' fields to zero.  Then
  1517.           `re_compile_pattern', it will allocate the memory for you.
  1518.  
  1519.  
  1520. Whether or not you allocate it, if the initial block in `buffer' isn't
  1521. large enough to hold the compiled pattern, then `re_compile_pattern'
  1522. will use the C library facility `realloc' (which is why you need to
  1523. allocate it using `malloc') to obtain as much memory as necessary and
  1524. reset the `allocated' field to the new buffer size.
  1525.  
  1526.   Leave the other fields alone.
  1527.  
  1528.   To compile a pattern buffer, use:
  1529.  
  1530.      char *
  1531.      re_compile_pattern (const char *REGEX, const int REGEX_SIZE,
  1532.                          struct re_pattern_buffer *PATTERN_BUFFER)
  1533.  
  1534. REGEX is the regular expression's address, REGEX_SIZE is its length,
  1535. and PATTERN_BUFFER is the pattern buffer's address.
  1536.  
  1537.   If `re_compile_pattern' successfully compiles the regular expression,
  1538. it returns zero and sets `*PATTERN_BUFFER' to the compiled pattern.  It
  1539. sets the pattern buffer's fields as follows:
  1540.  
  1541. `buffer'
  1542.      to the compiled pattern.
  1543.  
  1544. `syntax'
  1545.      to the current value of `re_syntax_options'.
  1546.  
  1547. `used'
  1548.      to the number of bytes the compiled pattern in `buffer' occupies.
  1549.  
  1550. `re_nsub'
  1551.      to the total number of subexpressions in the regular expression.
  1552.  
  1553. `fastmap_accurate'
  1554.      to zero on the theory that the pattern you're compiling is
  1555.      different than the one previously compiled into `buffer'; in that
  1556.      case (since you can't make a fastmap without a compiled pattern),
  1557.      `fastmap' would either contain an incompatible fastmap, or nothing
  1558.      at all.
  1559.  
  1560.   If `re_compile_pattern' can't compile REGEX, it returns an error
  1561. string.  You'll get one of the following.  *Note POSIX Regular
  1562. Expression Compiling:: for some examples.
  1563.  
  1564. 
  1565. File: regex.info,  Node: GNU Matching,  Next: GNU Searching,  Prev: GNU Regular Expression Compiling,  Up: GNU Regex Functions
  1566.  
  1567. GNU Matching
  1568. ------------
  1569.  
  1570.   Matching the GNU way means trying to match as much of a string as
  1571. possible starting at a position within it you specify.  Once you've
  1572. compiled a pattern into a pattern buffer (*note GNU Regular Expression
  1573. Compiling::.), you can ask the matcher to match that pattern against a
  1574. string using:
  1575.  
  1576.      int
  1577.      re_match (struct re_pattern_buffer *PATTERN_BUFFER,
  1578.                const char *STRING, const int SIZE,
  1579.                const int START, struct re_registers *REGS)
  1580.  
  1581. PATTERN_BUFFER is the address of a pattern buffer containing a compiled
  1582. pattern.  STRING is the string you want to match; it can contain
  1583. newline and null characters.  SIZE is the length of that string.  START
  1584. is the string index at which you want to begin matching; the first
  1585. character of STRING is at index zero. *Note Using Registers::, for a
  1586. explanation of REGS; you can safely pass zero.
  1587.  
  1588.   `re_match' matches the regular expression in PATTERN_BUFFER against
  1589. the string STRING according to the syntax in PATTERN_BUFFERS's `syntax'
  1590. field.  (*Note GNU Regular Expression Compiling::, for how to set it.) 
  1591. The function returns -1 if the compiled pattern does not match any part
  1592. of STRING and -2 if an internal error happens; otherwise, it returns
  1593. how many (possibly zero) characters of STRING the pattern buffer
  1594. matched.
  1595.  
  1596.   For example, suppose PATTERN_BUFFER points to a pattern buffer
  1597. containing the compiled pattern for `a*', and STRING points to `aaaaab'
  1598. (whereupon SIZE should be 6). Then if START is 2, `re_match' returns 3,
  1599. i.e., `a*' would have matched the last three `a's in STRING.  If START
  1600. is 0, `re_match' returns 5, i.e., `a*' would have matched all the `a's
  1601. in STRING.  If START is either 5 or 6, it returns zero.
  1602.  
  1603.   If START is not between zero and SIZE, then `re_match' returns -1.
  1604.  
  1605. 
  1606. File: regex.info,  Node: GNU Searching,  Next: Matching/Searching with Split Data,  Prev: GNU Matching,  Up: GNU Regex Functions
  1607.  
  1608. GNU Searching
  1609. -------------
  1610.  
  1611.   Searching the GNU way means trying to match a string starting at
  1612. successive positions within it, until the matcher has either found a
  1613. match or tried as many matches as you've asked for.  The function
  1614. `re_search' does this.  Ordinarily, `re_search' matches starting at
  1615. consecutive positions.  Initialize PATTERN_BUFFER's `fastmap' field to
  1616. zero if you want `re_search' to do this, or to a fastmap (*note
  1617. Searching with Fastmaps::.) if you want to make a search more
  1618. efficient.  Once you've compiled a pattern into a pattern buffer (*note
  1619. GNU Regular Expression Compiling::.), you can search a string for a
  1620. pattern using:
  1621.  
  1622.      int
  1623.      re_search (struct re_pattern_buffer *PATTERN_BUFFER,
  1624.                 const char *STRING, const int SIZE,
  1625.                 const int START, const int RANGE,
  1626.                 struct re_registers *REGS)
  1627.  
  1628. whose arguments are the same as those to `re_match' (*note GNU
  1629. Matching::.) except that the two arguments START and RANGE replace
  1630. `re_match''s argument START.
  1631.  
  1632.   If RANGE is positive, then `re_search' attempts a match starting
  1633. first at index START, then at START + 1 if that fails, and so on, up to
  1634. START + RANGE; if RANGE is negative, then it attempts a match starting
  1635. first at index START, then at START -1 if that fails, and so on.
  1636.  
  1637.   If no match is found, `re_search' returns -1.  If a match is found,
  1638. it returns the index where the match began.  If an internal error
  1639. happens, it returns -2.
  1640.  
  1641.   If START is not between zero and SIZE, then `re_search' returns -1. 
  1642. When RANGE is positive, `re_search' adjusts RANGE so that START + RANGE
  1643. - 1 is between zero and SIZE, if necessary; that way it won't search
  1644. outside of STRING.  Similarly, when RANGE is negative, `re_search'
  1645. adjusts RANGE so that START + RANGE + 1 is between zero and SIZE, if
  1646. necessary.
  1647.  
  1648. 
  1649. File: regex.info,  Node: Matching/Searching with Split Data,  Next: Searching with Fastmaps,  Prev: GNU Searching,  Up: GNU Regex Functions
  1650.  
  1651. Matching and Searching with Split Data
  1652. --------------------------------------
  1653.  
  1654.   Using the functions `re_match_2' and `re_search_2', you can match or
  1655. search in data that is divided into two strings.
  1656.  
  1657.   The function:
  1658.  
  1659.      int
  1660.      re_match_2 (struct re_pattern_buffer *BUFFER,
  1661.                  const char *STRING1, const int SIZE1,
  1662.                  const char *STRING2, const int SIZE2,
  1663.                  const int START,
  1664.                  struct re_registers *REGS,
  1665.                  const int STOP)
  1666.  
  1667. is similar to `re_match' (*note GNU Matching::.) except that you pass
  1668. *two* data strings and sizes, and an index STOP beyond which you don't
  1669. want the matcher to try matching.  As with `re_match', if it succeeds,
  1670. `re_match_2' returns how many characters of STRING it matched.  Regard
  1671. STRING1 and STRING2 as concatenated when you set the arguments START and
  1672. STOP and use the contents of REGS; `re_match_2' never returns a value
  1673. larger than SIZE1 + SIZE2.
  1674.  
  1675.   The function:
  1676.  
  1677.      int
  1678.      re_search_2 (struct re_pattern_buffer *BUFFER,
  1679.                   const char *STRING1, const int SIZE1,
  1680.                   const char *STRING2, const int SIZE2,
  1681.                   const int START, const int RANGE,
  1682.                   struct re_registers *REGS,
  1683.                   const int STOP)
  1684.  
  1685. is similarly related to `re_search'.
  1686.  
  1687. 
  1688. File: regex.info,  Node: Searching with Fastmaps,  Next: GNU Translate Tables,  Prev: Matching/Searching with Split Data,  Up: GNU Regex Functions
  1689.  
  1690. Searching with Fastmaps
  1691. -----------------------
  1692.  
  1693.   If you're searching through a long string, you should use a fastmap.
  1694. Without one, the searcher tries to match at consecutive positions in the
  1695. string.  Generally, most of the characters in the string could not start
  1696. a match.  It takes much longer to try matching at a given position in
  1697. the string than it does to check in a table whether or not the
  1698. character at that position could start a match.  A "fastmap" is such a
  1699. table.
  1700.  
  1701.   More specifically, a fastmap is an array indexed by the characters in
  1702. your character set.  Under the ASCII encoding, therefore, a fastmap has
  1703. 256 elements.  If you want the searcher to use a fastmap with a given
  1704. pattern buffer, you must allocate the array and assign the array's
  1705. address to the pattern buffer's `fastmap' field.  You either can
  1706. compile the fastmap yourself or have `re_search' do it for you; when
  1707. `fastmap' is nonzero, it automatically compiles a fastmap the first
  1708. time you search using a particular compiled pattern.
  1709.  
  1710.   To compile a fastmap yourself, use:
  1711.  
  1712.      int
  1713.      re_compile_fastmap (struct re_pattern_buffer *PATTERN_BUFFER)
  1714.  
  1715. PATTERN_BUFFER is the address of a pattern buffer.  If the character C
  1716. could start a match for the pattern, `re_compile_fastmap' makes
  1717. `PATTERN_BUFFER->fastmap[C]' nonzero.  It returns 0 if it can compile a
  1718. fastmap and -2 if there is an internal error.  For example, if `|' is
  1719. the alternation operator and PATTERN_BUFFER holds the compiled pattern
  1720. for `a|b', then `re_compile_fastmap' sets `fastmap['a']' and
  1721. `fastmap['b']' (and no others).
  1722.  
  1723.   `re_search' uses a fastmap as it moves along in the string: it checks
  1724. the string's characters until it finds one that's in the fastmap. Then
  1725. it tries matching at that character.  If the match fails, it repeats
  1726. the process.  So, by using a fastmap, `re_search' doesn't waste time
  1727. trying to match at positions in the string that couldn't start a match.
  1728.  
  1729.   If you don't want `re_search' to use a fastmap, store zero in the
  1730. `fastmap' field of the pattern buffer before calling `re_search'.
  1731.  
  1732.   Once you've initialized a pattern buffer's `fastmap' field, you need
  1733. never do so again--even if you compile a new pattern in it--provided
  1734. the way the field is set still reflects whether or not you want a
  1735. fastmap.  `re_search' will still either do nothing if `fastmap' is null
  1736. or, if it isn't, compile a new fastmap for the new pattern.
  1737.  
  1738. 
  1739. File: regex.info,  Node: GNU Translate Tables,  Next: Using Registers,  Prev: Searching with Fastmaps,  Up: GNU Regex Functions
  1740.  
  1741. GNU Translate Tables
  1742. --------------------
  1743.  
  1744.   If you set the `translate' field of a pattern buffer to a translate
  1745. table, then the GNU Regex functions to which you've passed that pattern
  1746. buffer use it to apply a simple transformation to all the regular
  1747. expression and string characters at which they look.
  1748.  
  1749.   A "translate table" is an array indexed by the characters in your
  1750. character set.  Under the ASCII encoding, therefore, a translate table
  1751. has 256 elements.  The array's elements are also characters in your
  1752. character set.  When the Regex functions see a character C, they use
  1753. `translate[C]' in its place, with one exception: the character after a
  1754. `\' is not translated.  (This ensures that, the operators, e.g., `\B'
  1755. and `\b', are always distinguishable.)
  1756.  
  1757.   For example, a table that maps all lowercase letters to the
  1758. corresponding uppercase ones would cause the matcher to ignore
  1759. differences in case.(1)  Such a table would map all characters except
  1760. lowercase letters to themselves, and lowercase letters to the
  1761. corresponding uppercase ones.  Under the ASCII encoding, here's how you
  1762. could initialize such a table (we'll call it `case_fold'):
  1763.  
  1764.      for (i = 0; i < 256; i++)
  1765.        case_fold[i] = i;
  1766.      for (i = 'a'; i <= 'z'; i++)
  1767.        case_fold[i] = i - ('a' - 'A');
  1768.  
  1769.   You tell Regex to use a translate table on a given pattern buffer by
  1770. assigning that table's address to the `translate' field of that buffer.
  1771.  If you don't want Regex to do any translation, put zero into this
  1772. field.  You'll get weird results if you change the table's contents
  1773. anytime between compiling the pattern buffer, compiling its fastmap, and
  1774. matching or searching with the pattern buffer.
  1775.  
  1776.   ---------- Footnotes ----------
  1777.  
  1778.   (1)  A table that maps all uppercase letters to the corresponding
  1779. lowercase ones would work just as well for this purpose.
  1780.  
  1781. 
  1782. File: regex.info,  Node: Using Registers,  Next: Freeing GNU Pattern Buffers,  Prev: GNU Translate Tables,  Up: GNU Regex Functions
  1783.  
  1784. Using Registers
  1785. ---------------
  1786.  
  1787.   A group in a regular expression can match a (posssibly empty)
  1788. substring of the string that regular expression as a whole matched. 
  1789. The matcher remembers the beginning and end of the substring matched by
  1790. each group.
  1791.  
  1792.   To find out what they matched, pass a nonzero REGS argument to a GNU
  1793. matching or searching function (*note GNU Matching::. and *Note GNU
  1794. Searching::), i.e., the address of a structure of this type, as defined
  1795. in `regex.h':
  1796.  
  1797.      struct re_registers
  1798.      {
  1799.        unsigned num_regs;
  1800.        regoff_t *start;
  1801.        regoff_t *end;
  1802.      };
  1803.  
  1804.   Except for (possibly) the NUM_REGS'th element (see below), the Ith
  1805. element of the `start' and `end' arrays records information about the
  1806. Ith group in the pattern.  (They're declared as C pointers, but this is
  1807. only because not all C compilers accept zero-length arrays;
  1808. conceptually, it is simplest to think of them as arrays.)
  1809.  
  1810.   The `start' and `end' arrays are allocated in various ways, depending
  1811. on the value of the `regs_allocated' field in the pattern buffer passed
  1812. to the matcher.
  1813.  
  1814.   The simplest and perhaps most useful is to let the matcher
  1815. (re)allocate enough space to record information for all the groups in
  1816. the regular expression.  If `regs_allocated' is `REGS_UNALLOCATED', the
  1817. matcher allocates 1 + RE_NSUB (another field in the pattern buffer;
  1818. *note GNU Pattern Buffers::.).  The extra element is set to -1, and
  1819. sets `regs_allocated' to `REGS_REALLOCATE'. Then on subsequent calls
  1820. with the same pattern buffer and REGS arguments, the matcher
  1821. reallocates more space if necessary.
  1822.  
  1823.   It would perhaps be more logical to make the `regs_allocated' field
  1824. part of the `re_registers' structure, instead of part of the pattern
  1825. buffer.  But in that case the caller would be forced to initialize the
  1826. structure before passing it.  Much existing code doesn't do this
  1827. initialization, and it's arguably better to avoid it anyway.
  1828.  
  1829.   `re_compile_pattern' sets `regs_allocated' to `REGS_UNALLOCATED', so
  1830. if you use the GNU regular expression functions, you get this behavior
  1831. by default.
  1832.  
  1833.   xx document re_set_registers
  1834.  
  1835.   POSIX, on the other hand, requires a different interface:  the caller
  1836. is supposed to pass in a fixed-length array which the matcher fills. 
  1837. Therefore, if `regs_allocated' is `REGS_FIXED' the matcher simply fills
  1838. that array.
  1839.  
  1840.   The following examples illustrate the information recorded in the
  1841. `re_registers' structure.  (In all of them, `(' represents the
  1842. open-group and `)' the close-group operator.  The first character in
  1843. the string STRING is at index 0.)
  1844.  
  1845.    * If the regular expression has an I-th group not contained within
  1846.      another group that matches a substring of STRING, then the
  1847.      function sets `REGS->start[I]' to the index in STRING where the
  1848.      substring matched by the I-th group begins, and `REGS->end[I]' to
  1849.      the index just beyond that substring's end.  The function sets
  1850.      `REGS->start[0]' and `REGS->end[0]' to analogous information about
  1851.      the entire pattern.
  1852.  
  1853.      For example, when you match `((a)(b))' against `ab', you get:
  1854.  
  1855.         * 0 in `REGS->start[0]' and 2 in `REGS->end[0]'
  1856.  
  1857.         * 0 in `REGS->start[1]' and 2 in `REGS->end[1]'
  1858.  
  1859.         * 0 in `REGS->start[2]' and 1 in `REGS->end[2]'
  1860.  
  1861.         * 1 in `REGS->start[3]' and 2 in `REGS->end[3]'
  1862.  
  1863.    * If a group matches more than once (as it might if followed by,
  1864.      e.g., a repetition operator), then the function reports the
  1865.      information about what the group *last* matched.
  1866.  
  1867.      For example, when you match the pattern `(a)*' against the string
  1868.      `aa', you get:
  1869.  
  1870.         * 0 in `REGS->start[0]' and 2 in `REGS->end[0]'
  1871.  
  1872.         * 1 in `REGS->start[1]' and 2 in `REGS->end[1]'
  1873.  
  1874.    * If the I-th group does not participate in a successful match,
  1875.      e.g., it is an alternative not taken or a repetition operator
  1876.      allows zero repetitions of it, then the function sets
  1877.      `REGS->start[I]' and `REGS->end[I]' to -1.
  1878.  
  1879.      For example, when you match the pattern `(a)*b' against the string
  1880.      `b', you get:
  1881.  
  1882.         * 0 in `REGS->start[0]' and 1 in `REGS->end[0]'
  1883.  
  1884.         * -1 in `REGS->start[1]' and -1 in `REGS->end[1]'
  1885.  
  1886.    * If the I-th group matches a zero-length string, then the function
  1887.      sets `REGS->start[I]' and `REGS->end[I]' to the index just beyond
  1888.      that zero-length string.
  1889.  
  1890.      For example, when you match the pattern `(a*)b' against the string
  1891.      `b', you get:
  1892.  
  1893.         * 0 in `REGS->start[0]' and 1 in `REGS->end[0]'
  1894.  
  1895.         * 0 in `REGS->start[1]' and 0 in `REGS->end[1]'
  1896.  
  1897.    * If an I-th group contains a J-th group in turn not contained
  1898.      within any other group within group I and the function reports a
  1899.      match of the I-th group, then it records in `REGS->start[J]' and
  1900.      `REGS->end[J]' the last match (if it matched) of the J-th group.
  1901.  
  1902.      For example, when you match the pattern `((a*)b)*' against the
  1903.      string `abb', group 2 last matches the empty string, so you get
  1904.      what it previously matched:
  1905.  
  1906.         * 0 in `REGS->start[0]' and 3 in `REGS->end[0]'
  1907.  
  1908.         * 2 in `REGS->start[1]' and 3 in `REGS->end[1]'
  1909.  
  1910.         * 2 in `REGS->start[2]' and 2 in `REGS->end[2]'
  1911.  
  1912.      When you match the pattern `((a)*b)*' against the string `abb',
  1913.      group 2 doesn't participate in the last match, so you get:
  1914.  
  1915.         * 0 in `REGS->start[0]' and 3 in `REGS->end[0]'
  1916.  
  1917.         * 2 in `REGS->start[1]' and 3 in `REGS->end[1]'
  1918.  
  1919.         * 0 in `REGS->start[2]' and 1 in `REGS->end[2]'
  1920.  
  1921.    * If an I-th group contains a J-th group in turn not contained
  1922.      within any other group within group I and the function sets
  1923.      `REGS->start[I]' and `REGS->end[I]' to -1, then it also sets
  1924.      `REGS->start[J]' and `REGS->end[J]' to -1.
  1925.  
  1926.      For example, when you match the pattern `((a)*b)*c' against the
  1927.      string `c', you get:
  1928.  
  1929.         * 0 in `REGS->start[0]' and 1 in `REGS->end[0]'
  1930.  
  1931.         * -1 in `REGS->start[1]' and -1 in `REGS->end[1]'
  1932.  
  1933.         * -1 in `REGS->start[2]' and -1 in `REGS->end[2]'
  1934.  
  1935. 
  1936. File: regex.info,  Node: Freeing GNU Pattern Buffers,  Prev: Using Registers,  Up: GNU Regex Functions
  1937.  
  1938. Freeing GNU Pattern Buffers
  1939. ---------------------------
  1940.  
  1941.   To free any allocated fields of a pattern buffer, you can use the
  1942. POSIX function described in *Note Freeing POSIX Pattern Buffers::,
  1943. since the type `regex_t'--the type for POSIX pattern buffers--is
  1944. equivalent to the type `re_pattern_buffer'.  After freeing a pattern
  1945. buffer, you need to again compile a regular expression in it (*note GNU
  1946. Regular Expression Compiling::.) before passing it to a matching or
  1947. searching function.
  1948.  
  1949. 
  1950. File: regex.info,  Node: POSIX Regex Functions,  Next: BSD Regex Functions,  Prev: GNU Regex Functions,  Up: Programming with Regex
  1951.  
  1952. POSIX Regex Functions
  1953. =====================
  1954.  
  1955.   If you're writing code that has to be POSIX compatible, you'll need
  1956. to use these functions. Their interfaces are as specified by POSIX,
  1957. draft 1003.2/D11.2.
  1958.  
  1959. * Menu:
  1960.  
  1961. * POSIX Pattern Buffers::               The regex_t type.
  1962. * POSIX Regular Expression Compiling::  regcomp ()
  1963. * POSIX Matching::                      regexec ()
  1964. * Reporting Errors::                    regerror ()
  1965. * Using Byte Offsets::                  The regmatch_t type.
  1966. * Freeing POSIX Pattern Buffers::       regfree ()
  1967.  
  1968. 
  1969. File: regex.info,  Node: POSIX Pattern Buffers,  Next: POSIX Regular Expression Compiling,  Up: POSIX Regex Functions
  1970.  
  1971. POSIX Pattern Buffers
  1972. ---------------------
  1973.  
  1974.   To compile or match a given regular expression the POSIX way, you
  1975. must supply a pattern buffer exactly the way you do for GNU (*note GNU
  1976. Pattern Buffers::.).  POSIX pattern buffers have type `regex_t', which
  1977. is equivalent to the GNU pattern buffer type `re_pattern_buffer'.
  1978.  
  1979. 
  1980. File: regex.info,  Node: POSIX Regular Expression Compiling,  Next: POSIX Matching,  Prev: POSIX Pattern Buffers,  Up: POSIX Regex Functions
  1981.  
  1982. POSIX Regular Expression Compiling
  1983. ----------------------------------
  1984.  
  1985.   With POSIX, you can only search for a given regular expression; you
  1986. can't match it.  To do this, you must first compile it in a pattern
  1987. buffer, using `regcomp'.
  1988.  
  1989.   Before calling `regcomp', you must initialize this pattern buffer as
  1990. you do for GNU (*note GNU Regular Expression Compiling::.).  See below,
  1991. however, for how to choose a syntax with which to compile.
  1992.  
  1993.   To compile a pattern buffer, use:
  1994.  
  1995.      int
  1996.      regcomp (regex_t *PREG, const char *REGEX, int CFLAGS)
  1997.  
  1998. PREG is the initialized pattern buffer's address, REGEX is the regular
  1999. expression's address, and CFLAGS is the compilation flags, which Regex
  2000. considers as a collection of bits.  Here are the valid bits, as defined
  2001. in `regex.h':
  2002.  
  2003. `REG_EXTENDED'
  2004.      says to use POSIX Extended Regular Expression syntax; if this isn't
  2005.      set, then says to use POSIX Basic Regular Expression syntax.
  2006.      `regcomp' sets PREG's `syntax' field accordingly.
  2007.  
  2008. `REG_ICASE'
  2009.      says to ignore case; `regcomp' sets PREG's `translate' field to a
  2010.      translate table which ignores case, replacing anything you've put
  2011.      there before.
  2012.  
  2013. `REG_NOSUB'
  2014.      says to set PREG's `no_sub' field; *note POSIX Matching::., for
  2015.      what this means.
  2016.  
  2017. `REG_NEWLINE'
  2018.      says that a:
  2019.  
  2020.         * match-any-character operator (*note Match-any-character
  2021.           Operator::.) doesn't match a newline.
  2022.  
  2023.         * nonmatching list not containing a newline (*note List
  2024.           Operators::.) matches a newline.
  2025.  
  2026.         * match-beginning-of-line operator (*note
  2027.           Match-beginning-of-line Operator::.) matches the empty string
  2028.           immediately after a newline, regardless of how `REG_NOTBOL'
  2029.           is set (*note POSIX Matching::., for an explanation of
  2030.           `REG_NOTBOL').
  2031.  
  2032.         * match-end-of-line operator (*note Match-beginning-of-line
  2033.           Operator::.) matches the empty string immediately before a
  2034.           newline, regardless of how `REG_NOTEOL' is set (*note POSIX
  2035.           Matching::., for an explanation of `REG_NOTEOL').
  2036.  
  2037.   If `regcomp' successfully compiles the regular expression, it returns
  2038. zero and sets `*PATTERN_BUFFER' to the compiled pattern. Except for
  2039. `syntax' (which it sets as explained above), it also sets the same
  2040. fields the same way as does the GNU compiling function (*note GNU
  2041. Regular Expression Compiling::.).
  2042.  
  2043.   If `regcomp' can't compile the regular expression, it returns one of
  2044. the error codes listed here.  (Except when noted differently, the
  2045. syntax of in all examples below is basic regular expression syntax.)
  2046.  
  2047. `REG_BADRPT'
  2048.      For example, the consecutive repetition operators `**' in `a**'
  2049.      are invalid.  As another example, if the syntax is extended
  2050.      regular expression syntax, then the repetition operator `*' with
  2051.      nothing on which to operate in `*' is invalid.
  2052.  
  2053. `REG_BADBR'
  2054.      For example, the COUNT `-1' in `a\{-1' is invalid.
  2055.  
  2056. `REG_EBRACE'
  2057.      For example, `a\{1' is missing a close-interval operator.
  2058.  
  2059. `REG_EBRACK'
  2060.      For example, `[a' is missing a close-list operator.
  2061.  
  2062. `REG_ERANGE'
  2063.      For example, the range ending point `z' that collates lower than
  2064.      does its starting point `a' in `[z-a]' is invalid.  Also, the
  2065.      range with the character class `[:alpha:]' as its starting point in
  2066.      `[[:alpha:]-|]'.
  2067.  
  2068. `REG_ECTYPE'
  2069.      For example, the character class name `foo' in `[[:foo:]' is
  2070.      invalid.
  2071.  
  2072. `REG_EPAREN'
  2073.      For example, `a\)' is missing an open-group operator and `\(a' is
  2074.      missing a close-group operator.
  2075.  
  2076. `REG_ESUBREG'
  2077.      For example, the back reference `\2' that refers to a nonexistent
  2078.      subexpression in `\(a\)\2' is invalid.
  2079.  
  2080. `REG_EEND'
  2081.      Returned when a regular expression causes no other more specific
  2082.      error.
  2083.  
  2084. `REG_EESCAPE'
  2085.      For example, the trailing backslash `\' in `a\' is invalid, as is
  2086.      the one in `\'.
  2087.  
  2088. `REG_BADPAT'
  2089.      For example, in the extended regular expression syntax, the empty
  2090.      group `()' in `a()b' is invalid.
  2091.  
  2092. `REG_ESIZE'
  2093.      Returned when a regular expression needs a pattern buffer larger
  2094.      than 65536 bytes.
  2095.  
  2096. `REG_ESPACE'
  2097.      Returned when a regular expression makes Regex to run out of
  2098.      memory.
  2099.  
  2100. 
  2101. File: regex.info,  Node: POSIX Matching,  Next: Reporting Errors,  Prev: POSIX Regular Expression Compiling,  Up: POSIX Regex Functions
  2102.  
  2103. POSIX Matching
  2104. --------------
  2105.  
  2106.   Matching the POSIX way means trying to match a null-terminated string
  2107. starting at its first character.  Once you've compiled a pattern into a
  2108. pattern buffer (*note POSIX Regular Expression Compiling::.), you can
  2109. ask the matcher to match that pattern against a string using:
  2110.  
  2111.      int
  2112.      regexec (const regex_t *PREG, const char *STRING,
  2113.               size_t NMATCH, regmatch_t PMATCH[], int EFLAGS)
  2114.  
  2115. PREG is the address of a pattern buffer for a compiled pattern. STRING
  2116. is the string you want to match.
  2117.  
  2118.   *Note Using Byte Offsets::, for an explanation of PMATCH.  If you
  2119. pass zero for NMATCH or you compiled PREG with the compilation flag
  2120. `REG_NOSUB' set, then `regexec' will ignore PMATCH; otherwise, you must
  2121. allocate it to have at least NMATCH elements.  `regexec' will record
  2122. NMATCH byte offsets in PMATCH, and set to -1 any unused elements up to
  2123. PMATCH`[NMATCH]' - 1.
  2124.  
  2125.   EFLAGS specifies "execution flags"--namely, the two bits `REG_NOTBOL'
  2126. and `REG_NOTEOL' (defined in `regex.h').  If you set `REG_NOTBOL', then
  2127. the match-beginning-of-line operator (*note Match-beginning-of-line
  2128. Operator::.) always fails to match. This lets you match against pieces
  2129. of a line, as you would need to if, say, searching for repeated
  2130. instances of a given pattern in a line; it would work correctly for
  2131. patterns both with and without match-beginning-of-line operators. 
  2132. `REG_NOTEOL' works analogously for the match-end-of-line operator
  2133. (*note Match-end-of-line Operator::.); it exists for symmetry.
  2134.  
  2135.   `regexec' tries to find a match for PREG in STRING according to the
  2136. syntax in PREG's `syntax' field. (*Note POSIX Regular Expression
  2137. Compiling::, for how to set it.)  The function returns zero if the
  2138. compiled pattern matches STRING and `REG_NOMATCH' (defined in
  2139. `regex.h') if it doesn't.
  2140.  
  2141. 
  2142. File: regex.info,  Node: Reporting Errors,  Next: Using Byte Offsets,  Prev: POSIX Matching,  Up: POSIX Regex Functions
  2143.  
  2144. Reporting Errors
  2145. ----------------
  2146.  
  2147.   If either `regcomp' or `regexec' fail, they return a nonzero error
  2148. code, the possibilities for which are defined in `regex.h'. *Note POSIX
  2149. Regular Expression Compiling::, and *Note POSIX Matching::, for what
  2150. these codes mean.  To get an error string corresponding to these codes,
  2151. you can use:
  2152.  
  2153.      size_t
  2154.      regerror (int ERRCODE, const regex_t *PREG, char *ERRBUF, size_t ERRBUF_SIZE)
  2155.  
  2156. ERRCODE is an error code, PREG is the address of the pattern buffer
  2157. which provoked the error, ERRBUF is the error buffer, and ERRBUF_SIZE
  2158. is ERRBUF's size.
  2159.  
  2160.   `regerror' returns the size in bytes of the error string
  2161. corresponding to ERRCODE (including its terminating null).  If ERRBUF
  2162. and ERRBUF_SIZE are nonzero, it also returns in ERRBUF the first
  2163. ERRBUF_SIZE - 1 characters of the error string, followed by a null.
  2164. ERRBUF_SIZE must be a nonnegative number less than or equal to the size
  2165. in bytes of ERRBUF.
  2166.  
  2167.   You can call `regerror' with a null ERRBUF and a zero ERRBUF_SIZE to
  2168. determine how large ERRBUF need be to accommodate `regerror''s error
  2169. string.
  2170.  
  2171. 
  2172. File: regex.info,  Node: Using Byte Offsets,  Next: Freeing POSIX Pattern Buffers,  Prev: Reporting Errors,  Up: POSIX Regex Functions
  2173.  
  2174. Using Byte Offsets
  2175. ------------------
  2176.  
  2177.   In POSIX, variables of type `regmatch_t' hold analogous information,
  2178. but are not identical to, GNU's registers (*note Using Registers::.). 
  2179. To get information about registers in POSIX, pass to `regexec' a
  2180. nonzero PMATCH of type `regmatch_t', i.e., the address of a structure
  2181. of this type, defined in `regex.h':
  2182.  
  2183.      typedef struct
  2184.      {
  2185.        regoff_t rm_so;
  2186.        regoff_t rm_eo;
  2187.      } regmatch_t;
  2188.  
  2189.   When reading in *Note Using Registers::, about how the matching
  2190. function stores the information into the registers, substitute PMATCH
  2191. for REGS, `PMATCH[I]->rm_so' for `REGS->start[I]' and
  2192. `PMATCH[I]->rm_eo' for `REGS->end[I]'.
  2193.  
  2194. 
  2195. File: regex.info,  Node: Freeing POSIX Pattern Buffers,  Prev: Using Byte Offsets,  Up: POSIX Regex Functions
  2196.  
  2197. Freeing POSIX Pattern Buffers
  2198. -----------------------------
  2199.  
  2200.   To free any allocated fields of a pattern buffer, use:
  2201.  
  2202.      void
  2203.      regfree (regex_t *PREG)
  2204.  
  2205. PREG is the pattern buffer whose allocated fields you want freed.
  2206. `regfree' also sets PREG's `allocated' and `used' fields to zero. 
  2207. After freeing a pattern buffer, you need to again compile a regular
  2208. expression in it (*note POSIX Regular Expression Compiling::.) before
  2209. passing it to the matching function (*note POSIX Matching::.).
  2210.  
  2211. 
  2212. File: regex.info,  Node: BSD Regex Functions,  Prev: POSIX Regex Functions,  Up: Programming with Regex
  2213.  
  2214. BSD Regex Functions
  2215. ===================
  2216.  
  2217.   If you're writing code that has to be Berkeley UNIX compatible,
  2218. you'll need to use these functions whose interfaces are the same as
  2219. those in Berkeley UNIX.
  2220.  
  2221. * Menu:
  2222.  
  2223. * BSD Regular Expression Compiling::    re_comp ()
  2224. * BSD Searching::                       re_exec ()
  2225.  
  2226. 
  2227. File: regex.info,  Node: BSD Regular Expression Compiling,  Next: BSD Searching,  Up: BSD Regex Functions
  2228.  
  2229. BSD Regular Expression Compiling
  2230. --------------------------------
  2231.  
  2232.   With Berkeley UNIX, you can only search for a given regular
  2233. expression; you can't match one.  To search for it, you must first
  2234. compile it.  Before you compile it, you must indicate the regular
  2235. expression syntax you want it compiled according to by setting the
  2236. variable `re_syntax_options' (declared in `regex.h' to some syntax
  2237. (*note Regular Expression Syntax::.).
  2238.  
  2239.   To compile a regular expression use:
  2240.  
  2241.      char *
  2242.      re_comp (char *REGEX)
  2243.  
  2244. REGEX is the address of a null-terminated regular expression. `re_comp'
  2245. uses an internal pattern buffer, so you can use only the most recently
  2246. compiled pattern buffer.  This means that if you want to use a given
  2247. regular expression that you've already compiled--but it isn't the
  2248. latest one you've compiled--you'll have to recompile it.  If you call
  2249. `re_comp' with the null string (*not* the empty string) as the
  2250. argument, it doesn't change the contents of the pattern buffer.
  2251.  
  2252.   If `re_comp' successfully compiles the regular expression, it returns
  2253. zero.  If it can't compile the regular expression, it returns an error
  2254. string.  `re_comp''s error messages are identical to those of
  2255. `re_compile_pattern' (*note GNU Regular Expression Compiling::.).
  2256.  
  2257. 
  2258. File: regex.info,  Node: BSD Searching,  Prev: BSD Regular Expression Compiling,  Up: BSD Regex Functions
  2259.  
  2260. BSD Searching
  2261. -------------
  2262.  
  2263.   Searching the Berkeley UNIX way means searching in a string starting
  2264. at its first character and trying successive positions within it to
  2265. find a match.  Once you've compiled a pattern using `re_comp' (*note
  2266. BSD Regular Expression Compiling::.), you can ask Regex to search for
  2267. that pattern in a string using:
  2268.  
  2269.      int
  2270.      re_exec (char *STRING)
  2271.  
  2272. STRING is the address of the null-terminated string in which you want
  2273. to search.
  2274.  
  2275.   `re_exec' returns either 1 for success or 0 for failure.  It
  2276. automatically uses a GNU fastmap (*note Searching with Fastmaps::.).
  2277.  
  2278. 
  2279. File: regex.info,  Node: Copying,  Next: Index,  Prev: Programming with Regex,  Up: Top
  2280.  
  2281. GNU GENERAL PUBLIC LICENSE
  2282. **************************
  2283.  
  2284.                          Version 2, June 1991
  2285.  
  2286.      Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  2287.      675 Mass Ave, Cambridge, MA 02139, USA
  2288.      
  2289.      Everyone is permitted to copy and distribute verbatim copies
  2290.      of this license document, but changing it is not allowed.
  2291.  
  2292. Preamble
  2293. ========
  2294.  
  2295.   The licenses for most software are designed to take away your freedom
  2296. to share and change it.  By contrast, the GNU General Public License is
  2297. intended to guarantee your freedom to share and change free
  2298. software--to make sure the software is free for all its users.  This
  2299. General Public License applies to most of the Free Software
  2300. Foundation's software and to any other program whose authors commit to
  2301. using it.  (Some other Free Software Foundation software is covered by
  2302. the GNU Library General Public License instead.)  You can apply it to
  2303. your programs, too.
  2304.  
  2305.   When we speak of free software, we are referring to freedom, not
  2306. price.  Our General Public Licenses are designed to make sure that you
  2307. have the freedom to distribute copies of free software (and charge for
  2308. this service if you wish), that you receive source code or can get it
  2309. if you want it, that you can change the software or use pieces of it in
  2310. new free programs; and that you know you can do these things.
  2311.  
  2312.   To protect your rights, we need to make restrictions that forbid
  2313. anyone to deny you these rights or to ask you to surrender the rights.
  2314. These restrictions translate to certain responsibilities for you if you
  2315. distribute copies of the software, or if you modify it.
  2316.  
  2317.   For example, if you distribute copies of such a program, whether
  2318. gratis or for a fee, you must give the recipients all the rights that
  2319. you have.  You must make sure that they, too, receive or can get the
  2320. source code.  And you must show them these terms so they know their
  2321. rights.
  2322.  
  2323.   We protect your rights with two steps: (1) copyright the software, and
  2324. (2) offer you this license which gives you legal permission to copy,
  2325. distribute and/or modify the software.
  2326.  
  2327.   Also, for each author's protection and ours, we want to make certain
  2328. that everyone understands that there is no warranty for this free
  2329. software.  If the software is modified by someone else and passed on, we
  2330. want its recipients to know that what they have is not the original, so
  2331. that any problems introduced by others will not reflect on the original
  2332. authors' reputations.
  2333.  
  2334.   Finally, any free program is threatened constantly by software
  2335. patents.  We wish to avoid the danger that redistributors of a free
  2336. program will individually obtain patent licenses, in effect making the
  2337. program proprietary.  To prevent this, we have made it clear that any
  2338. patent must be licensed for everyone's free use or not licensed at all.
  2339.  
  2340.   The precise terms and conditions for copying, distribution and
  2341. modification follow.
  2342.  
  2343.     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  2344.  
  2345.   1. This License applies to any program or other work which contains a
  2346.      notice placed by the copyright holder saying it may be distributed
  2347.      under the terms of this General Public License.  The "Program",
  2348.      below, refers to any such program or work, and a "work based on
  2349.      the Program" means either the Program or any derivative work under
  2350.      copyright law: that is to say, a work containing the Program or a
  2351.      portion of it, either verbatim or with modifications and/or
  2352.      translated into another language.  (Hereinafter, translation is
  2353.      included without limitation in the term "modification".)  Each
  2354.      licensee is addressed as "you".
  2355.  
  2356.      Activities other than copying, distribution and modification are
  2357.      not covered by this License; they are outside its scope.  The act
  2358.      of running the Program is not restricted, and the output from the
  2359.      Program is covered only if its contents constitute a work based on
  2360.      the Program (independent of having been made by running the
  2361.      Program). Whether that is true depends on what the Program does.
  2362.  
  2363.   2. You may copy and distribute verbatim copies of the Program's
  2364.      source code as you receive it, in any medium, provided that you
  2365.      conspicuously and appropriately publish on each copy an appropriate
  2366.      copyright notice and disclaimer of warranty; keep intact all the
  2367.      notices that refer to this License and to the absence of any
  2368.      warranty; and give any other recipients of the Program a copy of
  2369.      this License along with the Program.
  2370.  
  2371.      You may charge a fee for the physical act of transferring a copy,
  2372.      and you may at your option offer warranty protection in exchange
  2373.      for a fee.
  2374.  
  2375.   3. You may modify your copy or copies of the Program or any portion
  2376.      of it, thus forming a work based on the Program, and copy and
  2377.      distribute such modifications or work under the terms of Section 1
  2378.      above, provided that you also meet all of these conditions:
  2379.  
  2380.        a. You must cause the modified files to carry prominent notices
  2381.           stating that you changed the files and the date of any change.
  2382.  
  2383.        b. You must cause any work that you distribute or publish, that
  2384.           in whole or in part contains or is derived from the Program
  2385.           or any part thereof, to be licensed as a whole at no charge
  2386.           to all third parties under the terms of this License.
  2387.  
  2388.        c. If the modified program normally reads commands interactively
  2389.           when run, you must cause it, when started running for such
  2390.           interactive use in the most ordinary way, to print or display
  2391.           an announcement including an appropriate copyright notice and
  2392.           a notice that there is no warranty (or else, saying that you
  2393.           provide a warranty) and that users may redistribute the
  2394.           program under these conditions, and telling the user how to
  2395.           view a copy of this License.  (Exception: if the Program
  2396.           itself is interactive but does not normally print such an
  2397.           announcement, your work based on the Program is not required
  2398.           to print an announcement.)
  2399.  
  2400.      These requirements apply to the modified work as a whole.  If
  2401.      identifiable sections of that work are not derived from the
  2402.      Program, and can be reasonably considered independent and separate
  2403.      works in themselves, then this License, and its terms, do not
  2404.      apply to those sections when you distribute them as separate
  2405.      works.  But when you distribute the same sections as part of a
  2406.      whole which is a work based on the Program, the distribution of
  2407.      the whole must be on the terms of this License, whose permissions
  2408.      for other licensees extend to the entire whole, and thus to each
  2409.      and every part regardless of who wrote it.
  2410.  
  2411.      Thus, it is not the intent of this section to claim rights or
  2412.      contest your rights to work written entirely by you; rather, the
  2413.      intent is to exercise the right to control the distribution of
  2414.      derivative or collective works based on the Program.
  2415.  
  2416.      In addition, mere aggregation of another work not based on the
  2417.      Program with the Program (or with a work based on the Program) on
  2418.      a volume of a storage or distribution medium does not bring the
  2419.      other work under the scope of this License.
  2420.  
  2421.   4. You may copy and distribute the Program (or a work based on it,
  2422.      under Section 2) in object code or executable form under the terms
  2423.      of Sections 1 and 2 above provided that you also do one of the
  2424.      following:
  2425.  
  2426.        a. Accompany it with the complete corresponding machine-readable
  2427.           source code, which must be distributed under the terms of
  2428.           Sections 1 and 2 above on a medium customarily used for
  2429.           software interchange; or,
  2430.  
  2431.        b. Accompany it with a written offer, valid for at least three
  2432.           years, to give any third party, for a charge no more than your
  2433.           cost of physically performing source distribution, a complete
  2434.           machine-readable copy of the corresponding source code, to be
  2435.           distributed under the terms of Sections 1 and 2 above on a
  2436.           medium customarily used for software interchange; or,
  2437.  
  2438.        c. Accompany it with the information you received as to the offer
  2439.           to distribute corresponding source code.  (This alternative is
  2440.           allowed only for noncommercial distribution and only if you
  2441.           received the program in object code or executable form with
  2442.           such an offer, in accord with Subsection b above.)
  2443.  
  2444.      The source code for a work means the preferred form of the work for
  2445.      making modifications to it.  For an executable work, complete
  2446.      source code means all the source code for all modules it contains,
  2447.      plus any associated interface definition files, plus the scripts
  2448.      used to control compilation and installation of the executable. 
  2449.      However, as a special exception, the source code distributed need
  2450.      not include anything that is normally distributed (in either
  2451.      source or binary form) with the major components (compiler,
  2452.      kernel, and so on) of the operating system on which the executable
  2453.      runs, unless that component itself accompanies the executable.
  2454.  
  2455.      If distribution of executable or object code is made by offering
  2456.      access to copy from a designated place, then offering equivalent
  2457.      access to copy the source code from the same place counts as
  2458.      distribution of the source code, even though third parties are not
  2459.      compelled to copy the source along with the object code.
  2460.  
  2461.   5. You may not copy, modify, sublicense, or distribute the Program
  2462.      except as expressly provided under this License.  Any attempt
  2463.      otherwise to copy, modify, sublicense or distribute the Program is
  2464.      void, and will automatically terminate your rights under this
  2465.      License. However, parties who have received copies, or rights,
  2466.      from you under this License will not have their licenses
  2467.      terminated so long as such parties remain in full compliance.
  2468.  
  2469.   6. You are not required to accept this License, since you have not
  2470.      signed it.  However, nothing else grants you permission to modify
  2471.      or distribute the Program or its derivative works.  These actions
  2472.      are prohibited by law if you do not accept this License. 
  2473.      Therefore, by modifying or distributing the Program (or any work
  2474.      based on the Program), you indicate your acceptance of this
  2475.      License to do so, and all its terms and conditions for copying,
  2476.      distributing or modifying the Program or works based on it.
  2477.  
  2478.   7. Each time you redistribute the Program (or any work based on the
  2479.      Program), the recipient automatically receives a license from the
  2480.      original licensor to copy, distribute or modify the Program
  2481.      subject to these terms and conditions.  You may not impose any
  2482.      further restrictions on the recipients' exercise of the rights
  2483.      granted herein. You are not responsible for enforcing compliance
  2484.      by third parties to this License.
  2485.  
  2486.   8. If, as a consequence of a court judgment or allegation of patent
  2487.      infringement or for any other reason (not limited to patent
  2488.      issues), conditions are imposed on you (whether by court order,
  2489.      agreement or otherwise) that contradict the conditions of this
  2490.      License, they do not excuse you from the conditions of this
  2491.      License.  If you cannot distribute so as to satisfy simultaneously
  2492.      your obligations under this License and any other pertinent
  2493.      obligations, then as a consequence you may not distribute the
  2494.      Program at all.  For example, if a patent license would not permit
  2495.      royalty-free redistribution of the Program by all those who
  2496.      receive copies directly or indirectly through you, then the only
  2497.      way you could satisfy both it and this License would be to refrain
  2498.      entirely from distribution of the Program.
  2499.  
  2500.      If any portion of this section is held invalid or unenforceable
  2501.      under any particular circumstance, the balance of the section is
  2502.      intended to apply and the section as a whole is intended to apply
  2503.      in other circumstances.
  2504.  
  2505.      It is not the purpose of this section to induce you to infringe any
  2506.      patents or other property right claims or to contest validity of
  2507.      any such claims; this section has the sole purpose of protecting
  2508.      the integrity of the free software distribution system, which is
  2509.      implemented by public license practices.  Many people have made
  2510.      generous contributions to the wide range of software distributed
  2511.      through that system in reliance on consistent application of that
  2512.      system; it is up to the author/donor to decide if he or she is
  2513.      willing to distribute software through any other system and a
  2514.      licensee cannot impose that choice.
  2515.  
  2516.      This section is intended to make thoroughly clear what is believed
  2517.      to be a consequence of the rest of this License.
  2518.  
  2519.   9. If the distribution and/or use of the Program is restricted in
  2520.      certain countries either by patents or by copyrighted interfaces,
  2521.      the original copyright holder who places the Program under this
  2522.      License may add an explicit geographical distribution limitation
  2523.      excluding those countries, so that distribution is permitted only
  2524.      in or among countries not thus excluded.  In such case, this
  2525.      License incorporates the limitation as if written in the body of
  2526.      this License.
  2527.  
  2528.  10. The Free Software Foundation may publish revised and/or new
  2529.      versions of the General Public License from time to time.  Such
  2530.      new versions will be similar in spirit to the present version, but
  2531.      may differ in detail to address new problems or concerns.
  2532.  
  2533.      Each version is given a distinguishing version number.  If the
  2534.      Program specifies a version number of this License which applies
  2535.      to it and "any later version", you have the option of following
  2536.      the terms and conditions either of that version or of any later
  2537.      version published by the Free Software Foundation.  If the Program
  2538.      does not specify a version number of this License, you may choose
  2539.      any version ever published by the Free Software Foundation.
  2540.  
  2541.  11. If you wish to incorporate parts of the Program into other free
  2542.      programs whose distribution conditions are different, write to the
  2543.      author to ask for permission.  For software which is copyrighted
  2544.      by the Free Software Foundation, write to the Free Software
  2545.      Foundation; we sometimes make exceptions for this.  Our decision
  2546.      will be guided by the two goals of preserving the free status of
  2547.      all derivatives of our free software and of promoting the sharing
  2548.      and reuse of software generally.
  2549.  
  2550.                                 NO WARRANTY
  2551.  
  2552.  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  2553.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  2554.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  2555.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  2556.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  2557.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2558.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  2559.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  2560.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  2561.      SERVICING, REPAIR OR CORRECTION.
  2562.  
  2563.  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  2564.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  2565.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  2566.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  2567.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2568.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  2569.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  2570.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  2571.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  2572.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  2573.  
  2574.                       END OF TERMS AND CONDITIONS
  2575.  
  2576. Appendix: How to Apply These Terms to Your New Programs
  2577. =======================================================
  2578.  
  2579.   If you develop a new program, and you want it to be of the greatest
  2580. possible use to the public, the best way to achieve this is to make it
  2581. free software which everyone can redistribute and change under these
  2582. terms.
  2583.  
  2584.   To do so, attach the following notices to the program.  It is safest
  2585. to attach them to the start of each source file to most effectively
  2586. convey the exclusion of warranty; and each file should have at least
  2587. the "copyright" line and a pointer to where the full notice is found.
  2588.  
  2589.      ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
  2590.      Copyright (C) 19YY  NAME OF AUTHOR
  2591.      
  2592.      This program is free software; you can redistribute it and/or modify
  2593.      it under the terms of the GNU General Public License as published by
  2594.      the Free Software Foundation; either version 2 of the License, or
  2595.      (at your option) any later version.
  2596.      
  2597.      This program is distributed in the hope that it will be useful,
  2598.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  2599.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2600.      GNU General Public License for more details.
  2601.      
  2602.      You should have received a copy of the GNU General Public License
  2603.      along with this program; if not, write to the Free Software
  2604.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  2605.  
  2606.   Also add information on how to contact you by electronic and paper
  2607. mail.
  2608.  
  2609.   If the program is interactive, make it output a short notice like this
  2610. when it starts in an interactive mode:
  2611.  
  2612.      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  2613.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  2614.      This is free software, and you are welcome to redistribute it
  2615.      under certain conditions; type `show c' for details.
  2616.  
  2617.   The hypothetical commands `show w' and `show c' should show the
  2618. appropriate parts of the General Public License.  Of course, the
  2619. commands you use may be called something other than `show w' and `show
  2620. c'; they could even be mouse-clicks or menu items--whatever suits your
  2621. program.
  2622.  
  2623.   You should also get your employer (if you work as a programmer) or
  2624. your school, if any, to sign a "copyright disclaimer" for the program,
  2625. if necessary.  Here is a sample; alter the names:
  2626.  
  2627.      Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  2628.      `Gnomovision' (which makes passes at compilers) written by James Hacker.
  2629.      
  2630.      SIGNATURE OF TY COON, 1 April 1989
  2631.      Ty Coon, President of Vice
  2632.  
  2633.   This General Public License does not permit incorporating your
  2634. program into proprietary programs.  If your program is a subroutine
  2635. library, you may consider it more useful to permit linking proprietary
  2636. applications with the library.  If this is what you want to do, use the
  2637. GNU Library General Public License instead of this License.
  2638.  
  2639. 
  2640. File: regex.info,  Node: Index,  Prev: Copying,  Up: Top
  2641.  
  2642. Index
  2643. *****
  2644.  
  2645. * Menu:
  2646.  
  2647. * $:                                    Match-end-of-line Operator.
  2648. * (:                                    Grouping Operators.
  2649. * ):                                    Grouping Operators.
  2650. * *:                                    Match-zero-or-more Operator.
  2651. * +:                                    Match-one-or-more Operator.
  2652. * -:                                    List Operators.
  2653. * .:                                    Match-any-character Operator.
  2654. * :] in regex:                          Character Class Operators.
  2655. * ?:                                    Match-zero-or-one Operator.
  2656. * {:                                    Interval Operators.
  2657. * }:                                    Interval Operators.
  2658. * [: in regex:                          Character Class Operators.
  2659. * [^:                                   List Operators.
  2660. * [:                                    List Operators.
  2661. * \':                                   Match-end-of-buffer Operator.
  2662. * \<:                                   Match-beginning-of-word Operator.
  2663. * \>:                                   Match-end-of-word Operator.
  2664. * \{:                                   Interval Operators.
  2665. * \}:                                   Interval Operators.
  2666. * \B:                                   Match-within-word Operator.
  2667. * \S:                                   Match-not-syntactic-class Operator.
  2668. * \W:                                   Match-non-word-constituent Operator.
  2669. * \`:                                   Match-beginning-of-buffer Operator.
  2670. * \b:                                   Match-word-boundary Operator.
  2671. * \s:                                   Match-syntactic-class Operator.
  2672. * \w:                                   Match-word-constituent Operator.
  2673. * \:                                    List Operators.
  2674. * ]:                                    List Operators.
  2675. * ^:                                    List Operators.
  2676. * Awk:                                  Predefined Syntaxes.
  2677. * Egrep:                                Predefined Syntaxes.
  2678. * Emacs:                                Predefined Syntaxes.
  2679. * Grep:                                 Predefined Syntaxes.
  2680. * POSIX Awk:                            Predefined Syntaxes.
  2681. * REGS_FIXED:                           Using Registers.
  2682. * REGS_REALLOCATE:                      Using Registers.
  2683. * REGS_UNALLOCATED:                     Using Registers.
  2684. * REG_ICASE:                            POSIX Regular Expression Compiling.
  2685. * RE_BACKSLASH_ESCAPE_IN_LIST:          Syntax Bits.
  2686. * RE_BK_PLUS_QM:                        Syntax Bits.
  2687. * RE_CHAR_CLASSES:                      Syntax Bits.
  2688. * RE_CONTEXT_INDEP_ANCHORS:             Syntax Bits.
  2689. * RE_CONTEXT_INDEP_ANCHORS (and ^):     Match-beginning-of-line Operator.
  2690. * RE_CONTEXT_INDEP_OPS:                 Syntax Bits.
  2691. * RE_CONTEXT_INVALID_OPS:               Syntax Bits.
  2692. * RE_DOT_NEWLINE:                       Syntax Bits.
  2693. * RE_DOT_NOT_NULL:                      Syntax Bits.
  2694. * RE_INTERVALS:                         Syntax Bits.
  2695. * RE_LIMITED_OPS:                       Syntax Bits.
  2696. * RE_NEWLINE_ALT:                       Syntax Bits.
  2697. * RE_NO_BK_BRACES:                      Syntax Bits.
  2698. * RE_NO_BK_PARENS:                      Syntax Bits.
  2699. * RE_NO_BK_REFS:                        Syntax Bits.
  2700. * RE_NO_BK_VBAR:                        Syntax Bits.
  2701. * RE_NO_EMPTY_RANGES:                   Syntax Bits.
  2702. * RE_UNMATCHED_RIGHT_PAREN_ORD:         Syntax Bits.
  2703. * \:                                    The Backslash Character.
  2704. * \(:                                   Grouping Operators.
  2705. * \):                                   Grouping Operators.
  2706. * \|:                                   Alternation Operator.
  2707. * ^:                                    Match-beginning-of-line Operator.
  2708. * alternation operator:                 Alternation Operator.
  2709. * alternation operator and ^:           Match-beginning-of-line Operator.
  2710. * anchoring:                            Anchoring Operators.
  2711. * anchors:                              Match-beginning-of-line Operator.
  2712. * anchors:                              Match-end-of-line Operator.
  2713. * back references:                      Back-reference Operator.
  2714. * backtracking:                         Alternation Operator.
  2715. * backtracking:                         Match-zero-or-more Operator.
  2716. * beginning-of-line operator:           Match-beginning-of-line Operator.
  2717. * bracket expression:                   List Operators.
  2718. * character classes:                    Character Class Operators.
  2719. * end in struct re_registers:           Using Registers.
  2720. * end-of-line operator:                 Match-end-of-line Operator.
  2721. * grouping:                             Grouping Operators.
  2722. * interval expression:                  Interval Operators.
  2723. * matching list:                        List Operators.
  2724. * matching newline:                     List Operators.
  2725. * newline_anchor field in pattern buffer: Match-beginning-of-line Operator.
  2726. * nonmatching list:                     List Operators.
  2727. * not_bol field in pattern buffer:      Match-beginning-of-line Operator.
  2728. * num_regs in struct re_registers:      Using Registers.
  2729. * open-group operator and ^:            Match-beginning-of-line Operator.
  2730. * or operator:                          Alternation Operator.
  2731. * parenthesizing:                       Grouping Operators.
  2732. * re_pattern_buffer:                    GNU Pattern Buffers.
  2733. * re_registers:                         Using Registers.
  2734. * regex.c:                              Overview.
  2735. * regex.h:                              Overview.
  2736. * regexp anchoring:                     Anchoring Operators.
  2737. * regs_allocated:                       Using Registers.
  2738. * regular expressions, syntax of:       Regular Expression Syntax.
  2739. * start in struct re_registers:         Using Registers.
  2740. * subexpressions:                       Grouping Operators.
  2741. * syntax bits:                          Syntax Bits.
  2742. * syntax of regular expressions:        Regular Expression Syntax.
  2743. * word boundaries, matching:            Match-word-boundary Operator.
  2744. * |:                                    Alternation Operator.
  2745.  
  2746.  
  2747. 
  2748. Tag Table:
  2749. Node: Top1050
  2750. Node: Overview4519
  2751. Node: Regular Expression Syntax6702
  2752. Node: Syntax Bits7872
  2753. Node: Predefined Syntaxes13974
  2754. Node: Collating Elements vs. Characters17715
  2755. Node: The Backslash Character18678
  2756. Node: Common Operators21835
  2757. Node: Match-self Operator23288
  2758. Node: Match-any-character Operator23784
  2759. Node: Concatenation Operator24363
  2760. Node: Repetition Operators24859
  2761. Node: Match-zero-or-more Operator25278
  2762. Node: Match-one-or-more Operator27323
  2763. Node: Match-zero-or-one Operator28181
  2764. Node: Interval Operators29036
  2765. Node: Alternation Operator30830
  2766. Node: List Operators32320
  2767. Node: Character Class Operators35104
  2768. Node: Range Operator36736
  2769. Node: Grouping Operators38766
  2770. Node: Back-reference Operator40085
  2771. Node: Anchoring Operators42909
  2772. Node: Match-beginning-of-line Operator43283
  2773. Node: Match-end-of-line Operator44615
  2774. Node: GNU Operators45354
  2775. Node: Word Operators45603
  2776. Node: Non-Emacs Syntax Tables46226
  2777. Node: Match-word-boundary Operator47300
  2778. Node: Match-within-word Operator47693
  2779. Node: Match-beginning-of-word Operator48090
  2780. Node: Match-end-of-word Operator48423
  2781. Node: Match-word-constituent Operator48743
  2782. Node: Match-non-word-constituent Operator49069
  2783. Node: Buffer Operators49380
  2784. Node: Match-beginning-of-buffer Operator49787
  2785. Node: Match-end-of-buffer Operator50099
  2786. Node: GNU Emacs Operators50393
  2787. Node: Syntactic Class Operators50736
  2788. Node: Emacs Syntax Tables51142
  2789. Node: Match-syntactic-class Operator51798
  2790. Node: Match-not-syntactic-class Operator52395
  2791. Node: What Gets Matched?52985
  2792. Node: Programming with Regex53626
  2793. Node: GNU Regex Functions54064
  2794. Node: GNU Pattern Buffers54905
  2795. Node: GNU Regular Expression Compiling58183
  2796. Node: GNU Matching61530
  2797. Node: GNU Searching63458
  2798. Node: Matching/Searching with Split Data65412
  2799. Node: Searching with Fastmaps66868
  2800. Node: GNU Translate Tables69419
  2801. Node: Using Registers71391
  2802. Node: Freeing GNU Pattern Buffers77500
  2803. Node: POSIX Regex Functions78093
  2804. Node: POSIX Pattern Buffers78766
  2805. Node: POSIX Regular Expression Compiling79209
  2806. Node: POSIX Matching83539
  2807. Node: Reporting Errors85492
  2808. Node: Using Byte Offsets86703
  2809. Node: Freeing POSIX Pattern Buffers87517
  2810. Node: BSD Regex Functions88124
  2811. Node: BSD Regular Expression Compiling88543
  2812. Node: BSD Searching89915
  2813. Node: Copying90617
  2814. Node: Index109778
  2815. 
  2816. End Tag Table
  2817.