Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go

Regexp Quantifiers

20180608 Quantifiers are used to match repitition of a pattern within a string. The following table shows a list of quantifiers.

  Quantifier Description
1 * The preceeding item is matched 0 or more times
2 + The preceeding item is matched 1 or more times
3 ? The preceeding item is matched at most 1 times.
4 {n} The preceeding item is matched n times.
5 {n,} The preceeding item is matched atleast n times.

Some examples will illustrate.
s <- c("aaab", "abb", "bc", "abbcd", "bbbc", "abab", "caa")
grep(pattern="ab*b", s, value=TRUE)
## [1] "aaab"  "abb"   "abbcd" "abab"
grep(pattern="abbc?", s, value=TRUE)
## [1] "abb"   "abbcd"
grep(pattern="b{2,}?", s, value=TRUE)
## [1] "abb"   "abbcd" "bbbc"

Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.