home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / REGEXP.ZIP / REGEXP.DOC < prev    next >
Text File  |  1986-04-26  |  11KB  |  265 lines

  1.  
  2.  
  3.  
  4.      RRRREEEEGGGGEEEEXXXXPPPP((((3333))))               UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll))))                RRRREEEEGGGGEEEEXXXXPPPP((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           regcomp, regexec, regsub, regerror - regular expression
  10.           handler
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.           ####iiiinnnncccclllluuuuddddeeee <<<<rrrreeeeggggeeeexxxxpppp....hhhh>>>>
  14.  
  15.           rrrreeeeggggeeeexxxxpppp ****rrrreeeeggggccccoooommmmpppp((((eeeexxxxpppp))))
  16.           cccchhhhaaaarrrr ****eeeexxxxpppp;;;;
  17.  
  18.           iiiinnnntttt rrrreeeeggggeeeexxxxeeeecccc((((pppprrrroooogggg,,,, ssssttttrrrriiiinnnngggg))))
  19.           rrrreeeeggggeeeexxxxpppp ****pppprrrroooogggg;;;;
  20.           cccchhhhaaaarrrr ****ssssttttrrrriiiinnnngggg;;;;
  21.  
  22.           rrrreeeeggggssssuuuubbbb((((pppprrrroooogggg,,,, ssssoooouuuurrrrcccceeee,,,, ddddeeeesssstttt))))
  23.           rrrreeeeggggeeeexxxxpppp ****pppprrrroooogggg;;;;
  24.           cccchhhhaaaarrrr ****ssssoooouuuurrrrcccceeee;;;;
  25.           cccchhhhaaaarrrr ****ddddeeeesssstttt;;;;
  26.  
  27.           rrrreeeeggggeeeerrrrrrrroooorrrr((((mmmmssssgggg))))
  28.           cccchhhhaaaarrrr ****mmmmssssgggg;;;;
  29.  
  30.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  31.           These functions implement _e_g_r_e_p(1)-style regular expressions
  32.           and supporting facilities.
  33.  
  34.           _R_e_g_c_o_m_p compiles a regular expression into a structure of
  35.           type _r_e_g_e_x_p, and returns a pointer to it.  The space has
  36.           been allocated using _m_a_l_l_o_c(3) and may be released by _f_r_e_e.
  37.  
  38.           _R_e_g_e_x_e_c matches a NUL-terminated _s_t_r_i_n_g against the compiled
  39.           regular expression in _p_r_o_g.  It returns 1 for success and 0
  40.           for failure, and adjusts the contents of _p_r_o_g's _s_t_a_r_t_p and
  41.           _e_n_d_p (see below) accordingly.
  42.  
  43.           The members of a _r_e_g_e_x_p structure include at least the
  44.           following (not necessarily in order):
  45.  
  46.                char *startp[NSUBEXP];
  47.                char *endp[NSUBEXP];
  48.  
  49.           where _N_S_U_B_E_X_P is defined (as 10) in the header file.  Once a
  50.           successful _r_e_g_e_x_e_c has been done using the _r_e_g_e_x_p, each
  51.           _s_t_a_r_t_p-_e_n_d_p pair describes one substring within the _s_t_r_i_n_g,
  52.           with the _s_t_a_r_t_p pointing to the first character of the
  53.           substring and the _e_n_d_p pointing to the first character
  54.           following the substring.  The 0th substring is the substring
  55.           of _s_t_r_i_n_g that matched the whole regular expression.  The
  56.           others are those substrings that matched parenthesized
  57.           expressions within the regular expression, with
  58.           parenthesized expressions numbered in left-to-right order of
  59.           their opening parentheses.
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 4/11/86)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      RRRREEEEGGGGEEEEXXXXPPPP((((3333))))               UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll))))                RRRREEEEGGGGEEEEXXXXPPPP((((3333))))
  71.  
  72.  
  73.  
  74.           _R_e_g_s_u_b copies _s_o_u_r_c_e to _d_e_s_t, making substitutions according
  75.           to the most recent _r_e_g_e_x_e_c performed using _p_r_o_g.  Each
  76.           instance of `&' in _s_o_u_r_c_e is replaced by the substring
  77.           indicated by _s_t_a_r_t_p[_0] and _e_n_d_p[_0].  Each instance of `\_n',
  78.           where _n is a digit, is replaced by the substring indicated
  79.           by _s_t_a_r_t_p[_n] and _e_n_d_p[_n].  To get a literal `&' or `\_n' into
  80.           _d_e_s_t, prefix it with `\'; to get a literal `\' preceding `&'
  81.           or `\_n', prefix it with another `\'.
  82.  
  83.           _R_e_g_e_r_r_o_r is called whenever an error is detected in _r_e_g_c_o_m_p,
  84.           _r_e_g_e_x_e_c, or _r_e_g_s_u_b.  The default _r_e_g_e_r_r_o_r writes the string
  85.           _m_s_g, with a suitable indicator of origin, on the standard
  86.           error output and invokes _e_x_i_t(2).  _R_e_g_e_r_r_o_r can be replaced
  87.           by the user if other actions are desirable.
  88.  
  89.      RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNN SSSSYYYYNNNNTTTTAAAAXXXX
  90.           A regular expression is zero or more _b_r_a_n_c_h_e_s, separated by
  91.           `|'.  It matches anything that matches one of the branches.
  92.  
  93.           A branch is zero or more _p_i_e_c_e_s, concatenated.  It matches a
  94.           match for the first, followed by a match for the second,
  95.           etc.
  96.  
  97.           A piece is an _a_t_o_m possibly followed by `*', `+', or `?'.
  98.           An atom followed by `*' matches a sequence of 0 or more
  99.           matches of the atom.  An atom followed by `+' matches a
  100.           sequence of 1 or more matches of the atom.  An atom followed
  101.           by `?' matches a match of the atom, or the null string.
  102.  
  103.           An atom is a regular expression in parentheses (matching a
  104.           match for the regular expression), a _r_a_n_g_e (see below), `.'
  105.           (matching any single character), `^' (matching the null
  106.           string at the beginning of the input string), `$' (matching
  107.           the null string at the end of the input string), a `\'
  108.           followed by a single character (matching that character), or
  109.           a single character with no other significance (matching that
  110.           character).
  111.  
  112.           A _r_a_n_g_e is a sequence of characters enclosed in `[]'.  It
  113.           normally matches any single character from the sequence.  If
  114.           the sequence begins with `^', it matches any single
  115.           character _n_o_t from the rest of the sequence.  If two
  116.           characters in the sequence are separated by `-', this is
  117.           shorthand for the full list of ASCII characters between them
  118.           (e.g. `[0-9]' matches any decimal digit).  To include a
  119.           literal `]' in the sequence, make it the first character
  120.           (following a possible `^').  To include a literal `-', make
  121.           it the first or last character.
  122.  
  123.      AAAAMMMMBBBBIIIIGGGGUUUUIIIITTTTYYYY
  124.           If a regular expression could match two different parts of
  125.           the input string, it will match the one which begins
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 4/11/86)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      RRRREEEEGGGGEEEEXXXXPPPP((((3333))))               UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll))))                RRRREEEEGGGGEEEEXXXXPPPP((((3333))))
  137.  
  138.  
  139.  
  140.           earliest.  If both begin in the same place    but match
  141.           different lengths, or match the same length in different
  142.           ways, life gets messier, as follows.
  143.  
  144.           In general, the possibilities in a list of branches are
  145.           considered in left-to-right order, the possibilities for
  146.           `*', `+', and `?' are considered longest-first, nested
  147.           constructs are considered from the outermost in, and
  148.           concatenated constructs are considered leftmost-first.  The
  149.           match that will be chosen is the one that uses the earliest
  150.           possibility in the first choice that has to be made.  If
  151.           there is more than one choice, the next will be made in the
  152.           same manner (earliest possibility) subject to the decision
  153.           on the first choice.  And so forth.
  154.  
  155.           For example, `(ab|a)b*c' could match `abc' in one of two
  156.           ways.  The first choice is between `ab' and `a'; since `ab'
  157.           is earlier, and does lead to a successful overall match, it
  158.           is chosen.  Since the `b' is already spoken for, the `b*'
  159.           must match its last possibility-the empty string-since it
  160.           must respect the earlier choice.
  161.  
  162.           In the particular case where no `|'s are present and there
  163.           is only one `*', `+', or `?', the net effect is that the
  164.           longest possible match will be chosen.  So `ab*', presented
  165.           with `xabbbby', will match `abbbb'.  Note that if `ab*' is
  166.           tried against `xabyabbbz', it will match `ab' just after
  167.           `x', due to the begins-earliest rule.  (In effect, the
  168.           decision on where to start the match is the first choice to
  169.           be made, hence subsequent choices must respect it even if
  170.           this leads them to less-preferred alternatives.)
  171.  
  172.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  173.           egrep(1), expr(1)
  174.  
  175.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  176.           _R_e_g_c_o_m_p returns NULL for a failure (_r_e_g_e_r_r_o_r permitting),
  177.           where failures are syntax errors, exceeding implementation
  178.           limits, or applying `+' or `*' to a possibly-null operand.
  179.  
  180.      HHHHIIIISSSSTTTTOOOORRRRYYYY
  181.           Both code and manual page were written at U of T.  They are
  182.           intended to be compatible with the Bell V8 _r_e_g_e_x_p(3), but
  183.           are not derived from Bell code.
  184.  
  185.      BBBBUUUUGGGGSSSS
  186.           Empty branches and empty regular expressions are not
  187.           portable to V8.
  188.  
  189.           The restriction against applying `*' or `+' to a possibly-
  190.           null operand is an artifact of the simplistic
  191.           implementation.
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 4/11/86)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      RRRREEEEGGGGEEEEXXXXPPPP((((3333))))               UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll))))                RRRREEEEGGGGEEEEXXXXPPPP((((3333))))
  203.  
  204.  
  205.  
  206.           Does not support _e_g_r_e_p's newline-separated branches; neither
  207.           does the V8 _r_e_g_e_x_p(3), though.
  208.  
  209.           Due to emphasis on compactness and simplicity, it's not
  210.           strikingly fast.  It does give special attention to handling
  211.           simple cases quickly.
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 4/11/86)
  262.  
  263.  
  264.  
  265.