To detect Meta characters in regular expression with R
Meta characters are special operators that regular expressions do not capture.
Meta characters are . \ | ( ) [ ] { } $ * + ?
These meta characters should be prefixed with double backslash (\) in order to detect them using regular expression
In order to find a double backslash in a string, we need to prefix it with another double backslash.
Sequences contain special characters used to describe a pattern in a given string.
\d | Matches a digit character |
\D | Matches a Non-digit character |
\s | Matches a space character |
\S | Matches a non-space character |
\w | Matches a word character |
\W | Matches a Non-word character |
\b | Matches a word boundary |
\B | Matches a Non-word boundary |
#To find the index position of the character vector containing the given pattern
grep(“[aeiou]”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”,”AEIOU”))
#To get the character vector containing the given pattern
grep(“[aeiou]”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”),value=TRUE)
#To get the logical value(TRUE or FALSE) of the character vector containing the pattern
grepl(“[aeiou]”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”))
#To match the pattern with case sensitive
grep(“[aeiou]”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”,”AEIOU”),ignore.case=TRUE)
#To match the given pattern with character vector as it is
grep(“aeiou”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”,”AEIOU”),fixed = TRUE)
#To return the character vector that do not contain the gven pattern
grep(“[aeiou]”,c(“apple”,”bat”,”cat”,”Crypt”,”dog”,”elephant”,”Flag”,”aeiou”,”AEIOU”),invert = TRUE)