home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7393 < prev    next >
Encoding:
Text File  |  1992-12-13  |  1.7 KB  |  40 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!europa.asd.contel.com!howland.reston.ans.net!wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!seunet!enea!sommar
  3. From: sommar@enea.se (Erland Sommarskog)
  4. Subject: Another RE query
  5. Message-ID: <1992Dec13.150325.9754@enea.se>
  6. Organization: Enea Data AB
  7. Date: Sun, 13 Dec 1992 15:03:25 GMT
  8. Lines: 30
  9.  
  10. According to the FAQ you cannot handle balanced text with Perl's
  11. regular expressions, and it seems that what I'm trying to handle
  12. is just that. But I'd like to check out with the expertise just 
  13. in case.
  14.  
  15. Basically what I'm writing is a simple text formatter in which 
  16. user-defined strings are converted to escape-sequences for enscript.
  17. Those strings occurs in pairs to mark start and end of the text
  18. to be in deviating font. Anyway, innocently I tried something
  19. like:
  20.  
  21.     s!${start}((.|\n)*${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
  22.  
  23. But of course I got bitten if the pair twice in the same paragraph.
  24. (I read text paragraph by paragraph, a deliberate restriction.) Would
  25. $stop be guaranteed to be one character long, it would be trivial:
  26.  
  27.     s!${start}([^${stop}]*)${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
  28.  
  29. But $start and $stop can be any length, although would only expect
  30. one or two characters in practice. But two characters is enough to
  31. kill the idea. (Another problem is that the pairs may be nested,
  32. but I ignore that case.)
  33.  
  34. Since it seems this can't be done with regular expressions, I've
  35. redone the whole thing with index and substr like I would have
  36. done in a more traditional language. Still I would to check out
  37. that I didn't miss anything...
  38. -- 
  39. Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
  40.