fork download
  1. some_string <- "1_2018_start_2007_3_end"
  2. sub(".*?_(\\d{4})_.*", "\\1", some_string) # leftmost
  3. sub(".*_(\\d{4})_.*", "\\1", some_string) # rightmost
Success #stdin #stdout 0.16s 175424KB
stdin
Standard input is empty
stdout
[1] "2018"
[1] "2007"