markdown_link <- list(
"\\[",
title=".*?",
"\\]\\(",
url="http.*?",
"\\)")
markdown_subject <- "before [foo](http) between [bar text](http) after\n"
nc::capture_all_str(markdown_subject, markdown_link)
before_link <- nc::before_match(markdown_link)
(all_dt <- nc::capture_all_str(markdown_subject, before_link))
## before + match = full subject.
identical(all_dt[, paste(paste0(before, match), collapse="")], markdown_subject)
## replace with org link.
all_dt[, paste(paste0(before, ifelse(
.I==.N, "", sprintf("[[%s][%s]]", url, title)
)), collapse="")]
Run the code above in your browser using DataLab