Try gregexpr
with perl=TRUE
and use perl regular expressions with look-ahead assertions (see ?regex
):
gregexpr("(?=CC)","CCCGTGCC",perl=TRUE)
[[1]]
[1] 1 2 7
attr(,"match.length")
[1] 0 0 0
More Related Contents:
- Selecting data frame rows based on partial string match in a column
- How to use grep()/gsub() to find exact match
- How to remove all whitespace from a string?
- Using regex in R to find strings as whole words (but not strings as part of words)
- Replace multiple letters with accents with gsub
- Replace specific characters within strings
- Test if characters are in a string
- Remove parentheses and text within from strings in R
- Replace / translate characters in a string
- POSIX character class does not work in base R regex
- Remove part of a string
- regular expressions in base R: ‘perl=TRUE’ vs. the default (PCRE vs. TRE)
- Extracting unique numbers from string in R
- Remove everything after space in string
- gsub() in R is not replacing ‘.’ (dot)
- Select columns based on string match – dplyr::select
- in R, use gsub to remove all punctuation except period
- Use grepl to search either of multiple substrings in a text [duplicate]
- remove all line breaks (enter symbols) from the string using R
- R grep: is there an AND operator?
- How to remove unicode from string?
- Remove all punctuation except apostrophes in R
- select columns based on multiple strings with dplyr contains()
- How to delete everything after nth delimiter in R?
- Check if string contains ONLY NUMBERS or ONLY CHARACTERS (R)
- pivot_longer into multiple columns
- Remove part of a string in dataframe column (R)
- How to strsplit using ‘|’ character, it behaves unexpectedly?
- How to grep a word exactly
- remove text after final period in string