Skip to content

function and examples for matching entire file #35

@tdhock

Description

@tdhock

from https://tdhock.github.io/blog/2026/links-to-bibtex/

 link_pattern <- list(
  "\\[",
  title=".*?",
  "\\]\\(",
  url="http.*?",
  "\\)")
  before_pattern <- list(
    before="(?s).*?",
    nc::alternatives(
      link=link_pattern,
      "$"))

more generic

before <- function(...)list(
  before="(?s).*?",
  nc::alternatives(
    pattern=list(...),
    "$"))
nc::capture_all_str(
  "before [foo](http) between [bar text](http) after",
  before(
    "\\[",
    title=".*?",
    "\\]\\(",
    url="http.*?",
    "\\)"))

output

> nc::capture_all_str(
+ "before [foo](http) between [bar text](http) after",
+ before(
+ "\\[",
+ title=".*?",
+ "\\]\\(",
+ url="http.*?",
+ "\\)"))
      before          pattern    title    url
      <char>           <char>   <char> <char>
1:   before       [foo](http)      foo   http
2:  between  [bar text](http) bar text   http
3:     after                                 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions