home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / util / cdro / 003 / regexp.hlp < prev    next >
Encoding:
Text File  |  1993-02-19  |  3.2 KB  |  62 lines

  1. A regular expression is zero or more  branches , separated by `|'.
  2. It matches anything that matches one of the branches.
  3.  
  4. A branch is zero or more  pieces , concatenated.
  5. It matches a match for the first, followed by a match for the second, etc.
  6.  
  7. A piece is an  atom  possibly followed by `*', `+', or `?'.
  8. An atom followed by `*' matches a sequence of 0 or more matches of the atom.
  9. An atom followed by `+' matches a sequence of 1 or more matches of the atom.
  10. An atom followed by `?' matches a match of the atom, or the null string.
  11.  
  12. An atom is a regular expression in parentheses (matching a match for the
  13. regular expression), a  range  (see below), `.'
  14. (matching any single character), `^' (matching the null string at the
  15. beginning of the input string), `$' (matching the null string at the
  16. end of the input string), a `\' followed by a single character (matching
  17. that character), or a single character with no other significance
  18. (matching that character).
  19.  
  20. A  range  is a sequence of characters enclosed in `[]'.
  21. It normally matches any single character from the sequence.
  22. If the sequence begins with `^',
  23. it matches any single character  not  from the rest of the sequence.
  24. If two characters in the sequence are separated by ` ', this is shorthand
  25. for the full list of ASCII characters between them
  26. (e.g. `[0-9]' matches any decimal digit).
  27. To include a literal `]' in the sequence, make it the first character
  28. (following a possible `^').
  29. To include a literal ` ', make it the first or last character.
  30.  AMBIGUITY
  31. If a regular expression could match two different parts of the input string,
  32. it will match the one which begins earliest.
  33. If both begin in the same place    but match different lengths, or match
  34. the same length in different ways, life gets messier, as follows.
  35.  
  36. In general, the possibilities in a list of branches are considered in
  37. left-to-right order, the possibilities for `*', `+', and `?' are
  38. considered longest-first, nested constructs are considered from the
  39. outermost in, and concatenated constructs are considered leftmost-first.
  40. The match that will be chosen is the one that uses the earliest
  41. possibility in the first choice that has to be made.
  42. If there is more than one choice, the next will be made in the same manner
  43. (earliest possibility) subject to the decision on the first choice.
  44. And so forth.
  45.  
  46. For example, `(ab|a)b*c' could match `abc' in one of two ways.
  47. The first choice is between `ab' and `a'; since `ab' is earlier, and does
  48. lead to a successful overall match, it is chosen.
  49. Since the `b' is already spoken for,
  50. the `b*' must match its last possibility the empty string since
  51. it must respect the earlier choice.
  52.  
  53. In the particular case where no `|'s are present and there is only one
  54. `*', `+', or `?', the net effect is that the longest possible
  55. match will be chosen.
  56. So `ab*', presented with `xabbbby', will match `abbbb'.
  57. Note that if `ab*' is tried against `xabyabbbz', it
  58. will match `ab' just after `x', due to the begins-earliest rule.
  59. (In effect, the decision on where to start the match is the first choice
  60. to be made, hence subsequent choices must respect it even if this leads them
  61. to less-preferred alternatives.)
  62.