home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / emacs / 3874 < prev    next >
Encoding:
Internet Message Format  |  1992-12-28  |  2.5 KB

  1. Xref: sparky comp.emacs:3874 gnu.emacs.help:5188 gnu.epoch.misc:1221
  2. Path: sparky!uunet!spool.mu.edu!hri.com!noc.near.net!lynx!random.ccs.northeastern.edu!news
  3. From: ratinox@meceng.coe.northeastern.edu (Lemming Productions Present...)
  4. Newsgroups: comp.emacs,gnu.emacs.help,gnu.epoch.misc
  5. Subject: Re: strange replace-regexp behavior
  6. Message-ID: <RATINOX.92Dec28122732@splinter.coe.northeastern.edu>
  7. Date: 28 Dec 92 17:28:34 GMT
  8. References: <1992Dec28.133923.27974@nsisrv.gsfc.nasa.gov>
  9. Sender: news@random.ccs.northeastern.edu
  10. Organization: 3WA, Boston Office. Or Nu Meta Chi. Take your pick.
  11. Lines: 35
  12. In-Reply-To: pat@gsfc.nasa.gov's message of Mon, 28 Dec 1992 13: 39:23 GMT
  13. Nntp-Posting-Host: splinter.coe.northeastern.edu
  14. X-Posting-Software: GNUS 3.14.1 [ NNTP-based News Reader for GNU Emacs ]
  15. X-Signature-Virus-Protection: Version 1.51
  16. X-Get-A-Clue: Have two, they're small.
  17.  
  18. >>>>> On Mon, 28 Dec 1992 13:39:23 GMT, pat@gsfc.nasa.gov (patrick m. ryan)
  19. >>>>> said:
  20.  
  21. Patrick>     I was trying to remove a leading column of '>' characters
  22. Patrick> from some text and got some strange behavior from replace-regexp.
  23. Patrick> I have text something like this:
  24.  
  25. >In article 999, joe@blow said:
  26. >>blah blah blah
  27. >> blah blah blah
  28.  
  29. Patrick> I wanted to remove the first '>' in each line.  Thus, I did:
  30.  
  31. Patrick>     (replace-regexp "^>" "")
  32.  
  33. Patrick> Instead of removing just the first '>' in each line, it removed
  34. Patrick> the whole sequence of '>' characters.  It acted as though I
  35. Patrick> has used "^>*" for the first argument.  I ended up with:
  36.  
  37. Ok, here's the deal. What emacs does is to do a re-search-forward for your
  38. search string, deletes it, and inserts the replacement string. There goes
  39. the "^>". Now, it repeats the re-search-forward. Lo and behold, point is
  40. sitting just to the left of the search string "^>". It gleefully replaces
  41. it with the replacement string, and repeats itself.
  42.  
  43. You may want to use querey-replace-regexp instead. Or do two replace-regexp
  44. commands, the first change "^>" into something else, like "><", then do a
  45. second replace-regexp on the new string.
  46.  
  47. --Rat                               PGP Public Key Block available upon request
  48. ||||| | | | |  |  |  |   |   |    |    |    |   |   |  |  |  |  | | | | | |||||
  49. Northeastern's Stainless Steel Rat          ratinox@meceng.coe.northeastern.edu
  50. Love is a snowmobile racing across the tundra and then suddenly it flips over,
  51. pinning you underneath. At night, the ice weasels come.
  52.                                                  --Nietzsche [or Matt Groening]
  53.