| before_match | R Documentation |
Augment pattern so that it can be used to match an entire string. Useful for complex find and replace operations, when used with capture_all_str.
before_match(...)
... |
pattern as in |
Pattern with two new groups, before (everything before ...) and match (text matching ... or blank for end of string).
Toby Hocking <toby.hocking@r-project.org> [aut, cre]
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(
match=="", "", sprintf("[[%s][%s]]", url, title)
)), collapse="")]
## also works with no extra text before/after match.
nc::capture_all_str("[foo](http) between [bar text](http)", before_link)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.