Skip to content

Instantly share code, notes, and snippets.

@PietrH
Created June 26, 2019 08:01
Show Gist options
  • Save PietrH/dbbfcd66eb3948e93e924ae7f94b47f6 to your computer and use it in GitHub Desktop.
Save PietrH/dbbfcd66eb3948e93e924ae7f94b47f6 to your computer and use it in GitHub Desktop.
R grepl Function, REGEX examples
#Orignial Source: http://www.endmemo.com/program/R/grepl.php
#grepl returns TRUE if a string contains the pattern, otherwise FALSE; if the parameter is a string vector,
#returns a logical vector (match or not for each element of the vector).
grepl(pattern, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
#pattern: regular expression, or string for fixed=TRUE
#x: string, the character vector
#ignore.case: case sensitive or not#
#perl: logical. Should perl-compatible regexps be used? Has priority over extended
#fixed: logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments
#useBytes: logical. If TRUE the matching is done byte-by-byte rather than character-by-character
##REGEX EXAMPLES
all_dates <-
filter(all_dates, grepl("\\d", all_dates$DATES)) #keep rows with digits
all_dates <-
filter(all_dates, !grepl("[a-z]", all_dates$DATES)) #drops rows with letters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment