

No problem. I think this is a great “final boss” question for learning sed, because it turns out it is deceptively hard!! You have to understand not only a lot about regex, but about sed to get it right. I learned a lot about sed just by tackling this problem!
I really do not want to mess around with your regex
It is very delicate for sure, but one part you can for sure change is at the # Add hyphens
part. In the regex you can see (%20|\.)
. These are a list of “characters” which get converted to hyphens. For example, you could modify it to (%20|\.|\+)
and it will convert +
s to -
s as well!
Still it is not perfect:
- If the link spans multiple lines, the regex won’t match
- If the link contains escaped characters like
\\\\\[LINK](#LINK)
or[
]\\\\]( - If the link is inside a code block ``` it will get changed (which may or may not be intended)
But for a sed-only solution this is about as good as it will get I’m afraid.
Overall I’m very happy with it. Someday I would like to make a video that goes into depth about sed, since it is tricky to learn just from the docs.
To me, sentences ending in a period feel immutable, and without nuance, but sentences without a period feel incomplete, or up to change. Without periods it is almost a way to say, “this is what I think right now, but I might reconsider.” So, it’s not that periods are rude per-se, but it may appear that you’ve made up your mind and are closed off to interpretation. Sometimes I intentionally remove periods or turn it into an ellipsis for exactly that reason. It’s just way too easy to misinterpret people’s intentions through text for me not to type in a way I think reduces misinterpretation.
As for being associated with older people… anecdotally speaking, my co workers sound like they were taught that there is an immutable, proper way in the world, and so they express themself in that proper way. Nothing wrong with that really! Once I get a feel for their personality, I find it kind of endearing :)