regmatches("line_start 1 abc 2 def 4", gregexpr("(?:\\G(?!^)|^line_start)\\D*\\K\\d+", "line_start 1 abc 2 def 4", perl=TRUE)) library(stringr) stringr::str_extract_all("line_start 1 abc 2 def 4", "\\G\\D*?(\\d+)")