I want numeric values without alphabets

It would be nice if I could remove the alphabets from the numbers.
For example,


times <- c("01:10 22 Mar", "13:15", "04:25 10 Jun", "23:30", "10:25 13 Mar", "05:05 02 Mar", "10:25 13 Mar", "19:15", "23:00", "09:20 10 May", "19:50", "19:15 04 Mar", "13:15", "12:35 13 Jun", "19:15 13 Jun", "12:35 28 May")

The desired output should look like this:
times <- c("01:10", "13:15", "04:25", "23:30", "10:25", "05:05", "10:25", "19:15", "23:00", "09:20", "19:50", "19:15", "13:15", "12:35", "19:15", "12:35")

Here's what I tried:

times <- str_replace_all(times, "[^\\d]", "")

This is what I got:
times <- c("011022", "1315", "042510", "2330", "102513", "050502", "102513", "1915", "2300", "092010", "1950", "191504", "1315", "123513", "191513", "123528")

My searches for similar topics online turned up some, but in different programming languages or entirely new.

There are other numbers, the dates as well.
So in fact you want to extract the times, defined as (2 digits):(2digits), now you just need to define the Regex to find this:

times_out <- str_extract(times, "\\d{2}\\:\\d{2}")
times_out
[1] "01:10" "13:15" "04:25" "23:30" "10:25" "05:05" "10:25" "19:15" "23:00" "09:20" "19:50" "19:15" "13:15" "12:35" "19:15" "12:35"

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.