x <- c("not line_start 1 abc 2 def 4", "line_start 1 abc 2 def 4")
regmatches(x, gregexpr("(?:\\G(?!^)|^line_start)\\D*\\K\\d+", x, perl=TRUE))