With fixed pattern
stri_count_fixed("babab", "b")
# [1] 3
stri_count_fixed("babab", "ba")
# [1] 2
stri_count_fixed("babab", "bab")
# [1] 1
Natively:
length(gregexpr("b","babab")[[1]])
# [1] 3
length(gregexpr(...