The Dark Balloon

A weblog by Hao Lian.
A terrible secret guarded by golems.
A note that thanks you for being born, all those years ago.

§
My own idiom? Please, you’re too generous.

The problem is this: You have a file of many lines and you want to delete all the newlines except the ones that precede lines matching, let’s say, /^id:/. However, “id:” might appear on lines that start with something different. For example, lines matching /^alt_id:/. Hao’s idiom: Replace all newlines with a dummy character that never appears in the text. Something akin to s/\n/:::/g. Then do s/:::id:/\nid:/g. For the love of pie, I can’t figure out a sane way to shuffle this into one regex. Note that if you could negate captures like you can for character classes—something like /^([match any two letters except]id:)/—this would collapse to one regex. (Of course, you can always expand that out to permutations of character classes, but that scales exponentially for longer captures.)

[(2008 July 16) .]

I hear you. Perl’s negative look-ahead is pretty much useless in 99% of the cases.

I’m going to have to write a threatening letter to Larry Wall’s wife.

Abandon your ideas.

Use Markdown+, but not HTML. In code blocks, beware angle brackets.