home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Docs / regexp < prev    next >
Encoding:
Text File  |  1989-12-31  |  2.3 KB  |  64 lines

  1. Regular Expressions
  2.  
  3. Syntax
  4.  
  5. The code for handling regular expressions is derived from Henry Spencer's
  6. regexp package.  However, I have modified the syntax to resemble that of
  7. the real vi.
  8.  
  9. ELVIS' regexp package treats the following one- or two-character strings
  10. (called meta-characters) in special ways:
  11.  
  12.     \( \)    Used to control grouping
  13.     ^    Matches the beginning of a line
  14.     $    Matches the end of a line
  15.     \<    Matches the beginning of a word
  16.     \>    Matches the end of a word
  17.     .    Matches any single character
  18.     [ ]    Matches any single character inside the brackets
  19.     *    The preceding may be repeated 0 or more times
  20.     +    The preceding may be repeated 1 or more times
  21.     ?    The preceding is optional
  22.     \|    Separates two alternatives
  23.  
  24. Anything else is treated as a normal character which must match exactly.
  25. The special strings may all be preceded by a backslash to force them to
  26. be treated normally.
  27.  
  28. For example, "\(for\|back\)ward" will find "forward" or "backward", and
  29. "\<text\>" will find "text" but not "context".
  30.  
  31.  
  32. Options
  33.  
  34. ELVIS has two options which affect the way regular expressions are used.
  35. These options may be examined or set via the :set command.
  36.  
  37. The first option is called "[no]magic".  This is a boolean option, and it is
  38. "magic" (TRUE) by default.  While in magic mode, all of the meta-characters
  39. behave as described above.  In nomagic mode, only ^ and $ retain their
  40. special meaning.
  41.  
  42. The second option is called "[no]ignorecase".  This is a boolean option, and
  43. it is "noignorecase" (FALSE) by default.  While in ignorecase mode, the
  44. searching mechanism will not distinguish between an uppercase letter and its
  45. lowercase form.  In noignorecase mode, uppercase and lowercase are treated
  46. as being different.
  47.  
  48.  
  49. Substitutions
  50.  
  51. The :s command has at least two arguments: a regular expression, and a
  52. substitution string.  The text that matched the regular expression is
  53. replaced by text which is derived from the substitution string.
  54.  
  55. Most characters in the substitution string are copied into the text literally
  56. but a few have special meaning:
  57.  
  58.     &    Causes a copy of the original text to be inserted
  59.     \1    Inserts a copy of that portion of the original text which
  60.           matched the first set of \( \) parentheses.
  61.     \2 - \9    Does the same for the second (etc.) pair of \( \).
  62.  
  63. These may be preceded by a backslash to force them to be treated normally.
  64.