home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / ad12.zip / REGULAR.TXT < prev    next >
Text File  |  1992-04-21  |  9KB  |  206 lines

  1.                            ACTION DESIGNER
  2.                           SEARCHING FEATURES
  3.                              As of 4/20/92
  4.  
  5.  
  6.     The regular expression notation used by the searching routine is 
  7.     very similar to the standard notation defined by the UNIX editor ed.
  8.  
  9.     A regular expression (RE) specifies a set of character strings. A 
  10.     substring in the searched string is said to be matched by the RE 
  11.     if the substring is one of the character strings allowed by the RE.
  12.  
  13.     If you have never used regular expressions before, the notation
  14.     is a bit arcane.  You'll learn to love it.  I won't give up my 
  15.     Brief editor, even under Windows, until I find an editor with 
  16.     comparable RE capability.
  17.  
  18.  
  19.                     SIMPLE REGULAR EXPRESSIONS
  20.  
  21.     ORDINARY CHARACTERS
  22.     One kind of ordinary character is a one-character RE that matches 
  23.     itself.  
  24.  
  25.     The second kind of ordinary character is a two-character expression
  26.     that indicates that what would otherwise be a meta-character -- the
  27.     special characters described below -- is to be treated as an ordinary 
  28.     character.  The backslash is used as the first character in this 
  29.     sequence.
  30.      
  31.     BACKSLASH (\)
  32.     A backslash (\) followed by a meta-character is an RE that makes 
  33.     the metacharacter into an ordinary character.
  34.  
  35.     PERIOD
  36.     A period (.) is a one-character RE that matches any character.
  37.  
  38.     CHARACTER CLASS
  39.     A non-empty string of characters enclosed in square brackets ([]) 
  40.     is an RE that matches any one character in that string.  
  41.  
  42.             [STV] will match either an S or a T or a V.
  43.  
  44.     The following characters have special meanings within the square
  45.     brackets.
  46.  
  47.     ^       If the first character of the string is a circumflex (^), 
  48.             the RE matches any character except what the RE would 
  49.             otherwise match. The ^ has this special meaning only if 
  50.             it occurs first in the string.  
  51.  
  52.     -       The minus (-) may be used to indicate a range of consecutive 
  53.             ASCII characters.  For example, [0-9] is equivalent to 
  54.             [0123456789].
  55.  
  56.             The - loses this special meaning in the following cases:
  57.  
  58.               if the - occurs first
  59.                  the - occurs after an initial ^
  60.                  the - occurs last in the string.
  61.  
  62.               if the - is the first character after a range.
  63.                  For example, [0-9-a] would be matched by any of 
  64.                  the digits from 0 thru 9, by a dash, or by an a.
  65.  
  66.               if the - is the terminating character of a range. 
  67.                  For example, [+--a-z] would be matched by any of 
  68.                  the characters in the range + through - or
  69.                                      in the range a through z.
  70.  
  71.     ]       The right square bracket (]) does not terminate a string 
  72.             when it is the first character within it or after an 
  73.             initial ^.  E.g., []a-f] matches either a right square 
  74.             bracket (]) or one of the letters a through f.
  75.  
  76.  
  77.     THE POSITIONAL REGULAR EXPRESSION
  78.     The positional regular expression is used to indicate where in a
  79.     line of text an operation is to occur.  It is indicated by angle 
  80.     brackets <> enclosing one or more numbers.  For example:
  81.  
  82.     <0>     is an RE that matches the null string at position 0, 
  83.             the beginning of the string.
  84.  
  85.     <0,5,10> is an RE that matches the null string at position 0, 
  86.             or the null string at position 5, or the null string 
  87.             at position 10. 
  88.  
  89.     ~       End Of Line Specification:  If the position is preceeded 
  90.             by a tilda (~), then the position is measured from the 
  91.             end of the string.  
  92.  
  93.             <~0> matches the null string at the end of the string. 
  94.             <~4> matches the null string at position 4 counting
  95.                  from the end of the string. 
  96.  
  97.     -       Range Specification: If two positions are separated by 
  98.             a minus (-), a range of positions is used.  
  99.  
  100.             <0-5>  matches any of the null strings at positions 0 
  101.                    through 5,
  102.             <5-~5> matches any null string from position 5 counting 
  103.                    from the beginning to position 5 counting from 
  104.                    the end.  
  105.  
  106.             In a range specification, the second position specified 
  107.             must not occur before the first position specified.
  108.  
  109.             <5-~5> will always fail to match in a string of 9
  110.                    characters or less, since 5 positions from the 
  111.                    beginning occurs after 5 positions from the end.
  112.             <~0-~5> always fails.  <~5-~0> is correct.
  113.  
  114.  
  115.                     COMPLEX REGULAR EXPRESSIONS
  116.  
  117.     The following rules may be used to construct REs from other REs:
  118.  
  119.     *       An RE followed by an asterisk (*) is an RE that matches 
  120.             zero or more occurrences of the RE.  
  121.  
  122.             ab(ba)*cb searches for all occurences of ab followed by
  123.                       zero or more occurences of ba followed by cb. 
  124.                       The patterns abbacb, abbabacb, abbabababacb, 
  125.                       and abcb would all be treated as matching this
  126.                       RE.
  127.  
  128.             ab(ba)*   searches for all occurrences of ab followed by
  129.                       zero or more occurrences of ba.  If more than 
  130.                       one sequence of ba follows an ab in the text, 
  131.                       the match will be made to the entire sequence. 
  132.  
  133.             (ba)*     will always match the beginning of the string.
  134.  
  135.     +       An RE followed by a plus (+) is an RE that matches one 
  136.             or more occurrences of the RE.  
  137.  
  138.             ab(ba)+    searches for all occurences of ab followed by
  139.                        one or more occurrences of ba.  If more than
  140.                        one sequence of ba follows an ab in the text, 
  141.                        e.g., abbababa, the match will be made to the 
  142.                        entire sequence.
  143.  
  144.     {}      Replication Counts: An RE followed by {m}, {m,}, {,n} or 
  145.             {m,n} is an RE that matches a range of occurrences of the 
  146.             RE.  The values of m and n must be non-negative integers.  
  147.  
  148.             {m}     indicates exactly m occurrences of the RE.  
  149.  
  150.             {m,n}   If m is less than n, then {m,n} indicates at 
  151.                     least m occurrences of the RE and no more than 
  152.                     n occurrences.  In cases where the RE occurs
  153.                     more than the minimum number of times specified
  154.                     by m, the match will be made to the minimum
  155.                     number.
  156.                     
  157.                     ab(ba){2,4}:  if abbabababa is found, the match
  158.                                   will be made to abbaba.
  159.  
  160.                     If m is greater than or equal to n, then {m,n}
  161.                     indicates at least n occurrences of the RE and no 
  162.                     more than m occurrences.  In cases where the RE
  163.                     occurs more than the minimum number of times
  164.                     specified by n, the match will be made to the
  165.                     longest sequence up to and including the maximum
  166.                     number specified by m.
  167.  
  168.                     ab(ba){4,2}:  if abbabababa is found, the match will be
  169.                                   made to the entire sequence.
  170.  
  171.             {m,}    is equivalent to {m,infinity} and
  172.             {,n}    is equivalent to {infinity,n}.  
  173.  
  174.                     Consequently, * and + are 
  175.                     equivalent to {,0} and {,1} respectively.
  176.  
  177.     $       Assignment: An RE followed by $c where c is a letter
  178.             matches whatever the RE alone would match.  (Upper 
  179.             and lower case are equivalent.) 
  180.  
  181.             The expression <c> where c is a letter is an RE which 
  182.             matches whatever value is assigned to the character c.  
  183.             If no previous assignment has been made, then it matches 
  184.             the null string in any position.
  185.  
  186.     |       Alternation:  REs separated by a vertical bar (|) form an 
  187.             RE that will be matched by strings in the text that match
  188.             any of the REs that make up the complex RE.
  189.  
  190.             (s|x|z) will be matched by either an s, an x, or a z. 
  191.  
  192.     ()      Grouping: An RE enclosed within parentheses is equivalent 
  193.             in terms of what matches it to the same RE without the 
  194.             parentheses.
  195.  
  196.     CONCATENATION
  197.     REs may be concatenated together to form a single RE that will 
  198.     be matched by the concatenation of the strings that matched the 
  199.     previously separate REs.
  200.  
  201.     PRECEDENCE
  202.     The suffix operators *, +, {}, and $, have the highest precedence.  
  203.     Concatenation has next highest precedence.  Alternation, |, has 
  204.     the lowest precedence.  The order of operation may be modified by 
  205.     grouping with parentheses.
  206.