How to identify string with dots and number?

There is a variable with some values like abcd...134, flextime...258, treatment...625, etc. the last 6 digits are three dots plus three numbers. Is there a easy way to identify all such pattern values? Thank you!

You can use str_detect() from the stringr package to return TRUE or FALSE if the pattern is matched. I stored a set of possible strings in the vector called Var.

library(stringr)
Var <- c("abcd...134", "flextime...258", "treatment...625",
  "abcd", "..134", "...13")
str_detect(Var, "\\.{3}\\d{3}$")
#> [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE

Created on 2019-06-05 by the reprex package (v0.2.1)

2 Likes

It works. Thank you so much!

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