Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Use extended regexps with sed's -E option to avoid Leaning Toothpick Syndrome. Also, if ] is the first (optionally after a ^) character in a bracket expression, it doesn't need to be escaped (see man regex). e.g. echo '## [Some title](#some-title)' | sed -E 's/^(#+) *\[([^]]*)\].*/\1 \2/'. BTW, note the use of + after # instead of *. + means one-or-more, * means zero-or-more. It's each to match more than you mean if you use + instead of * - in this case, * would match ALL URLs, not just those in # headers. Commented Jul 18 at 3:27
  • ALL URLs at the beginning of a line starting with zero-or-more spaces, that is. Commented Jul 18 at 3:33
  • 1
    [^\]] is undefined behavior per POSIX so any sed can do whatever it likes with that. ITYM just []] instead. Commented Jul 18 at 12:21