home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4883 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.2 KB

  1. Path: sparky!uunet!usc!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!mintaka.lcs.mit.edu!ai-lab!life!jba
  2. From: jba@ai.mit.edu (Jonathan Amsterdam)
  3. Newsgroups: comp.lang.perl
  4. Subject: back-references in regexps
  5. Message-ID: <JBA.92Jul22141349@kix.ai.mit.edu>
  6. Date: 22 Jul 92 18:13:49 GMT
  7. Sender: news@ai.mit.edu
  8. Distribution: comp
  9. Organization: MIT Artificial Intelligence Laboratory
  10. Lines: 22
  11.  
  12. I've been looking closely at Perl regular expressions and have noticed some
  13. interesting things about back references:
  14.  
  15. 1. It is possible to have a valid back-reference (i.e. one that doesn't
  16.    always fail) inside its own paren. E.g. /(a(b|\1))+/
  17.  
  18. 2. It is possible to have a valid back-reference before its paren.
  19.    E.g. /(\2|(\w))+/
  20.  
  21. 3. A back-reference can succeed even if its paren was part of a failure
  22.    earlier in the scan.  E.g. /((ab)d|abc)\2/ will match "abcab".  
  23.  
  24.  
  25. I'm particularly interested in 3.  Is it a commonly known fact?  Is it
  26. considered a feature or a sort of fall-through-the-cracks don't-care kind
  27. of thing?  (One might at first believe, or even wish, that a back-reference
  28. to something that failed would also fail.)
  29.  
  30. Does anybody have any scripts that use any of the above three properties?
  31.  
  32.     Thanks,
  33.     Jonathan Amsterdam
  34.