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.)