Search notes:

R function: grep(…)

grep(regexp, vec) searches for strings in the character vector that match the regular expression regexp and returns a vector with the matched strings.
words=c("Foo", "Bar", "Baz", "One", "Two", "Three")

# grep returns a Vector of the indices of the matched elements (value=FALSE), or
# of the matched (value=TRUE)

grep("Ba", words, value=FALSE)
# [1] 2 3

grep("Ba", words, value=TRUE)
# [1] "Bar" "Baz"

# { Lowercase and uppercase

grep("o", words, value=TRUE)
# [1] "Foo" "Two"

grep("[Oo]", words, value=TRUE)
# [1] "Foo" "One" "Two"

# Perhaps the simplest case:
grep("o", words, value=TRUE, ignore.case=TRUE)
# [1] "Foo" "One" "Two"

# }

colors()[grep('red', colors())]
#  [1] "darkred"         "indianred"       "indianred1"      "indianred2"
#  [5] "indianred3"      "indianred4"      "mediumvioletred" "orangered"
#  [9] "orangered1"      "orangered2"      "orangered3"      "orangered4"
# [13] "palevioletred"   "palevioletred1"  "palevioletred2"  "palevioletred3"
# [17] "palevioletred4"  "red"             "red1"            "red2"
# [21] "red3"            "red4"            "violetred"       "violetred1"
# [25] "violetred2"      "violetred3"      "violetred4"
Github repository about-r, path: /functions/grep.R

See also

String related R functions, R regular expression functions.
Index to (some) R functions
The shell command grep.
The Perl function grep.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200825, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/grep(82): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78