home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!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
- From: sommar@enea.se (Erland Sommarskog)
- Subject: Re: Another RE query
- Message-ID: <1992Dec19.215441.11676@enea.se>
- Organization: Enea Data AB
- References: <1992Dec13.150325.9754@enea.se>
- Date: Sat, 19 Dec 1992 21:54:41 GMT
- Lines: 38
-
- A while ago I wrote:
- >Basically what I'm writing is a simple text formatter in which
- >user-defined strings are converted to escape-sequences for enscript.
- >Those strings occurs in pairs to mark start and end of the text
- >to be in deviating font. Anyway, innocently I tried something
- >like:
- >
- > s!${start}((.|\n)*${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
- >
- >But of course I got bitten if the pair twice in the same paragraph.
- >(I read text paragraph by paragraph, a deliberate restriction.) Would
- >$stop be guaranteed to be one character long, it would be trivial:
- >
- > s!${start}([^${stop}]*)${stop}!${esc}F${ch1}$1${esc}F${ch2}!g
- >
- >But $start and $stop can be any length, although would only expect
- >one or two characters in practice. But two characters is enough to
- >kill the idea.
-
- Randall Schwartz was quick to tell me that REs won't work, that's
- computer science, not Perl. But as I told him, I am writing this
- is Perl, not computer science.
-
- Anyway, I've come to conclusion that I can actually get what I
- want with regular expressions, if I introduce the restriction
- that if $start and $stop may only be equal, if they are one character
- long. Then I can look at $start and $stop and if they are equal,
- I can use the second substitution above - the one with [^${stop}].
- If they are not equal, I can simply subsitute them separately,
- and ignore what is in between.
-
- I'm not certain that this restriction is feasible. I might want
- to use equal $start and $stop like //, but surely not $%. (That
- would rather be $% and %$.) But if I find that the index and
- substr code that I've written - but not yet had the time to test -
- is too slow, this might be a path to go.
- --
- Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
-