Hello rstats folks!
I think I've totally forgotten my string manipulation skills Does anyone know how to match on a pattern in a vector, split on the pattern, but keep the pattern used to match?
library(tidyverse)
string_vector <- "05:52 The birch canoe slid on the smooth planks.05:53 These days a chicken leg is a rare dish..06:59 Four hours of steady work faced us."
# If can find the regular expression to match the time...
stringr::str_view_all(string_vector,
# match number format of 00:00
pattern = "\\d\\d:\\d\\d")
I tried stringr::str_split()
but it removes the regex...how can I split on the pattern and keep the text?
So it looks like this:
StringTibble <- tibble::tribble(
~time, ~text,
"05:52", "The birch canoe slid on the smooth planks",
"05:53", "These days a chicken leg is a rare dish",
"06:59", "Four hours of steady work faced us."
)
StringTibble
#> # A tibble: 3 x 2
#> time text
#> <chr> <chr>
#> 1 05:52 The birch canoe slid on the smooth planks
#> 2 05:53 These days a chicken leg is a rare dish
#> 3 06:59 Four hours of steady work faced us.
Thank you in advance!
Created on 2019-04-10 by the reprex package (v0.2.1)