str_start()
finds the beginning position of pattern
in each element of x
, while str_end()
finds the stopping position
of pattern
in each element of x
.
str_start(x, pattern, ignore.case = TRUE) str_end(x, pattern, ignore.case = TRUE)
x | A character vector. |
---|---|
pattern | Character string to be matched in |
ignore.case | Logical, whether matching should be case sensitive or not. |
A numeric vector with index of start/end position(s) of pattern
found in x
, or an empty vector, if pattern
was not found
in x
.
path <- "this/is/my/fileofinterest.csv" str_start(path, "/")#> [1] 5 8 11path <- "this//is//my//fileofinterest.csv" str_start(path, "//")#> [1] 5 9 13str_end(path, "//")#> [1] 6 10 14x <- c("my_friend_likes me", "your_friend likes_you") str_start(x, "_")#> [[1]] #> [1] 3 10 #> #> [[2]] #> [1] 5 18 #># pattern "likes" starts at position 11 in first, and # position 13 in second string str_start(x, "likes")#> [[1]] #> [1] 11 #> #> [[2]] #> [1] 13 #># pattern "likes" ends at position 15 in first, and # position 17 in second string str_end(x, "likes")#> [[1]] #> [1] 15 #> #> [[2]] #> [1] 17 #>x <- c("I like to move it, move it", "You like to move it") str_start(x, "move")#> [[1]] #> [1] 11 20 #> #> [[2]] #> [1] 13 #>str_end(x, "move")#> [[1]] #> [1] 14 23 #> #> [[2]] #> [1] 16 #>