Skip to content

Instantly share code, notes, and snippets.

@chrissyhroberts
Created April 8, 2021 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissyhroberts/18e87a0ecca02f0c9e1daf8403eb3fe1 to your computer and use it in GitHub Desktop.
Save chrissyhroberts/18e87a0ecca02f0c9e1daf8403eb3fe1 to your computer and use it in GitHub Desktop.
extract substrings before and after a match in r
#return text after match
a <- "asdfgpopgazelle"
data.table::tstrsplit(a, "pop")[[2]]
"gazelle"
#return all splits
a <- "asdfgpopgazelle"
> data.table::tstrsplit(a, "g")
[[1]]
[1] "asdf"
[[2]]
[1] "pop"
[[3]]
[1] "azelle"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment