Testing a string for a match

Regular expressions

data1 <- "aaab"
data2 <- "aaaba"
data3 <- "bbba"
# ^ anchors the start only; the end is free
pattern <- "^a+b"

b1 <- grepl(pattern, data1)
# b1 = TRUE
b2 <- grepl(pattern, data2)
# b2 = TRUE
b3 <- grepl(pattern, data3)
# b3 = FALSE

cat("b1 =", b1, "\n")
cat("b2 =", b2, "\n")
cat("b3 =", b3, "\n")