Finding a match

Regular expressions

data <- "Pi is equal to 3.14"
pattern <- r"(\d+\.\d+)"

# The matched text, or character(0) if none
found <- regmatches(data, regexpr(pattern, data))

if (length(found) > 0) {
  pi_value <- as.numeric(found)
  # pi_value = 3.14

  cat("pi_value =", pi_value, "\n")
}