home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.n / regexp.n < prev    next >
Encoding:
Text File  |  1995-07-26  |  9.8 KB  |  197 lines

  1.  
  2.  
  3.  
  4.      rrrreeeeggggeeeexxxxpppp((((nnnn))))                    TTTTccccllll (((( ))))                    rrrreeeeggggeeeexxxxpppp((((nnnn))))
  5.  
  6.  
  7.  
  8.      _________________________________________________________________
  9.  
  10.      NNNNAAAAMMMMEEEE
  11.           regexp - Match a regular expression against a string
  12.  
  13.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.           rrrreeeeggggeeeexxxxpppp  ?_s_w_i_t_c_h_e_s?  _e_x_p   _s_t_r_i_n_g   ?_m_a_t_c_h_V_a_r?   ?_s_u_b_M_a_t_c_h_V_a_r
  15.           _s_u_b_M_a_t_c_h_V_a_r ...?
  16.      _________________________________________________________________
  17.  
  18.  
  19.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  20.           Determines whether the regular expression _e_x_p  matches  part
  21.           or all of _s_t_r_i_n_g and returns 1 if it does, 0 if it doesn't.
  22.  
  23.           If additional arguments are specified after _s_t_r_i_n_g then they
  24.           are  treated  as  the  names of variables in which to return
  25.           information about  which  part(s)  of  _s_t_r_i_n_g  matched  _e_x_p.
  26.           _M_a_t_c_h_V_a_r will be set to the range of _s_t_r_i_n_g that matched all
  27.           of _e_x_p.  The first _s_u_b_M_a_t_c_h_V_a_r will contain  the  characters
  28.           in   _s_t_r_i_n_g   that   matched   the   leftmost  parenthesized
  29.           subexpression within _e_x_p, the next _s_u_b_M_a_t_c_h_V_a_r will  contain
  30.           the   characters   that   matched   the  next  parenthesized
  31.           subexpression to the right in _e_x_p, and so on.
  32.  
  33.           If the initial arguments to rrrreeeeggggeeeexxxxpppp start with  ----  then  they  |
  34.           are   treated  as  switches.   The  following  switches  are  |
  35.           currently supported:                                          |
  36.  
  37.           ----nnnnooooccccaaaasssseeee                                                            ||
  38.                     Causes  upper-case  characters  in  _s_t_r_i_n_g  to  be  |
  39.                     treated as lower case during the matching process.  |
  40.  
  41.           ----iiiinnnnddddiiiicccceeeessss                                                           ||
  42.                     Changes   what  is  stored  in  the  _s_u_b_M_a_t_c_h_V_a_rs.  |
  43.                     Instead of storing the  matching  characters  from  |
  44.                     ssssttttrrrriiiinnnngggg,  each  variable will contain a list of two  |
  45.                     decimal strings giving the indices  in  _s_t_r_i_n_g  of  |
  46.                     the  first  and  last  characters  in the matching  |
  47.                     range of characters.                                |
  48.  
  49.           --------                                                                 ||
  50.                     Marks the end of switches.  The argument following  |
  51.                     this one will be treated as _e_x_p even if it  starts  |
  52.                     with a ----....
  53.  
  54.           If  there  are   more   _s_u_b_M_a_t_c_h_V_a_r's   than   parenthesized
  55.           subexpressions  within _e_x_p, or if a particular subexpression
  56.           in _e_x_p doesn't match the string (e.g. because it  was  in  a
  57.           portion  of  the  expression  that wasn't matched), then the
  58.           corresponding _s_u_b_M_a_t_c_h_V_a_r  will  be  set  to  ``----1111  ----1111''  if
  59.           ----iiiinnnnddddiiiicccceeeessss has been specified or to an empty string otherwise.
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/17/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      rrrreeeeggggeeeexxxxpppp((((nnnn))))                    TTTTccccllll (((( ))))                    rrrreeeeggggeeeexxxxpppp((((nnnn))))
  71.  
  72.  
  73.  
  74.      RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNNSSSS
  75.           Regular expressions are implemented  using  Henry  Spencer's
  76.           package  (thanks,  Henry!),  and  much of the description of
  77.           regular expressions below is copied verbatim from his manual
  78.           entry.
  79.  
  80.           A regular expression is zero or more _b_r_a_n_c_h_e_s, separated  by
  81.           ``|''.    It  matches  anything  that  matches  one  of  the
  82.           branches.
  83.  
  84.           A branch is zero or more _p_i_e_c_e_s, concatenated.  It matches a
  85.           match  for  the  first,  followed by a match for the second,
  86.           etc.
  87.  
  88.           A piece is an _a_t_o_m possibly followed  by  ``*'',  ``+'',  or
  89.           ``?''.  An atom followed by ``*'' matches a sequence of 0 or
  90.           more matches of the atom.  An atom followed by ``+'' matches
  91.           a  sequence  of  1  or  more  matches  of the atom.  An atom
  92.           followed by ``?'' matches a match of the atom, or  the  null
  93.           string.
  94.  
  95.           An atom is a regular expression in parentheses  (matching  a
  96.           match  for  the  regular  expression),  a _r_a_n_g_e (see below),
  97.           ``.'' (matching any single character), ``^''  (matching  the
  98.           null  string  at  the  beginning of the input string), ``$''
  99.           (matching the null string at the end of the input string), a
  100.           ``\''   followed   by  a  single  character  (matching  that
  101.           character), or a single character with no other significance
  102.           (matching that character).
  103.  
  104.           A _r_a_n_g_e is a sequence of characters enclosed in ``[]''.   It
  105.           normally matches any single character from the sequence.  If
  106.           the sequence  begins  with  ``^'',  it  matches  any  single
  107.           character  _n_o_t  from  the  rest  of  the  sequence.   If two
  108.           characters in the sequence are separated by ``-'',  this  is
  109.           shorthand for the full list of ASCII characters between them
  110.           (e.g. ``[0-9]'' matches any decimal digit).   To  include  a
  111.           literal  ``]''  in the sequence, make it the first character
  112.           (following a possible ``^'').  To include a  literal  ``-'',
  113.           make it the first or last character.
  114.  
  115.  
  116.      CCCCHHHHOOOOOOOOSSSSIIIINNNNGGGG AAAAMMMMOOOONNNNGGGG AAAALLLLTTTTEEEERRRRNNNNAAAATTTTIIIIVVVVEEEE MMMMAAAATTTTCCCCHHHHEEEESSSS
  117.           In general there may be more than one way to match a regular
  118.           expression  to  an  input string.  For example, consider the
  119.           command
  120.  
  121.                rrrreeeeggggeeeexxxxpppp  ((((aaaa****))))bbbb****  aaaaaaaabbbbaaaaaaaaaaaabbbbbbbb  xxxx  yyyy
  122.           Considering only the rules given so far, xxxx and yyyy  could  end
  123.           up  with  the values aaaaaaaabbbbbbbb and aaaaaaaa, aaaaaaaaaaaabbbb and aaaaaaaaaaaa, aaaabbbb and aaaa, or
  124.           any  of  several  other  combinations.   To   resolve   this
  125.           potential  ambiguity rrrreeeeggggeeeexxxxpppp chooses among alternatives using
  126.  
  127.  
  128.      Page 2                                          (printed 7/17/95)
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.      rrrreeeeggggeeeexxxxpppp((((nnnn))))                    TTTTccccllll (((( ))))                    rrrreeeeggggeeeexxxxpppp((((nnnn))))
  136.  
  137.  
  138.  
  139.           the  rule  ``first  then  longest''.   In  other  words,  it
  140.           consders  the possible matches in order working from left to
  141.           right across the  input  string  and  the  pattern,  and  it
  142.           attempts  to  match longer pieces of the input string before
  143.           shorter ones.  More specifically, the following rules  apply
  144.           in decreasing order of priority:
  145.  
  146.           [1]  If a regular expression could match two different parts
  147.                of  an  input  string  then  it will match the one that
  148.                begins earliest.
  149.  
  150.           [2]  If a regular expression contains |||| operators  then  the
  151.                leftmost matching sub-expression is chosen.
  152.  
  153.           [3]  In ****, ++++, and ???? constructs, longer matches are chosen in
  154.                preference to shorter ones.
  155.  
  156.           [4]  In sequences of expression  components  the  components
  157.                are considered from left to right.
  158.  
  159.           In the example from above, ((((aaaa****))))bbbb****  matches  aaaaaaaabbbb:   the  ((((aaaa****))))
  160.           portion  of the pattern is matched first and it consumes the
  161.           leading aaaaaaaa; then the bbbb**** portion of the pattern consumes  the
  162.           next bbbb.  Or, consider the following example:
  163.  
  164.                rrrreeeeggggeeeexxxxpppp  ((((aaaabbbb||||aaaa))))((((bbbb****))))cccc  aaaabbbbcccc  xxxx  yyyy  zzzz
  165.           After this command xxxx will be aaaabbbbcccc, yyyy will be aaaabbbb, and  zzzz  will
  166.           be an empty string.  Rule 4 specifies that ((((aaaabbbb||||aaaa)))) gets first
  167.           shot at the input string and Rule 2 specifies  that  the  aaaabbbb
  168.           sub-expression is checked before the aaaa sub-expression.  Thus
  169.           the bbbb has already been claimed before the ((((bbbb****)))) component  is
  170.           checked and ((((bbbb****)))) must match an empty string.
  171.  
  172.  
  173.      KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  174.           match, regular expression, string
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.      Page 3                                          (printed 7/17/95)
  193.  
  194.  
  195.  
  196.