That's an admirable solution, which I'll be sure to generalize and use in
other contexts. Thank you.
Given that "1 while ..." logic works for my needs here, though, is there a
reason I should use the sexeger logic instead? Is the "1 while ..."
expression more costly? It seems, on the face of it, that the "1
while" is more readily decypherable by another programmer unfamiliar with
my coding style.
That perception, of the relative opacity of the sexeger, may be mistaken,
of course, and is at best a subjective judgement, so I wouldn't attach
much weight to it, given any substantial reason favoring the sexeger
expression as compared to the "1 while" expression.
best,
Eric Lawson
On Mon, 13 Aug 2001, Jeff 'japhy/Marillion' Pinyan wrote:
> The logic such a solution requires is this:
>
> "as long as we START with '%A ' and were preceded by a line that STARS
> with '%A ', remove the '\n%A ' and replace it with a ';'"
>
> This is difficult to do with a regex, since the "preceded by" requires a
> look-behind, and you can't say (?<=%A .*\n), because look-behinds cannot
> be a variable width (and .* is variable width).
>
> So the solution I came up with was to reverse the string. Then we are
> dealing with look-aheads, which CAN be variable width.
>
> $_ = reverse;
> s/(.*) A%\n(?=.* A%)/$1;/g;
> $_ = reverse;
>
> Ta da. Let me explain that.
>
> 1. reverse the string
> 2. the regex:
> a. match text (store to $1)
> b. match " A%\n"
> c. AND BE SURE we're followed by ANOTHER "... A%" string
> 3. replace this with the matched text and a semicolon
> 4. reverse the string
>
> This is a technique I have come to embrace. I call it "sexeger" (because
> it involves reversing regexes) and it makes things that used to be
> impossible with a single regex possible.
>
> The beauty of the look-ahead is that it makes sure it COULD match without
> actually advancing in the string. That makes this work.
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]