regex - Detecting sequencing using regexes -
imagine have multiple character strings in list this:
[[1]]  [1] "1-fa-1-i2-1-i2-1-i2-1-ex-1-i2-1-i3-1-fa-1-"   [2] "-1-i2-1-tr-1-"                                [3] "-1-i2-1-fa-1-i3-1-"                           [4] "-1-fa-1-fa-1-nr-1-i3-1-i2-1-tr-1-"            [5] "-1-i2-1-"                                     [6] "-1-i2-1-fa-1-i2-1-"                           [7] "-1-i3-1-fa-1-qu-1-"                           [8] "-1-i2-1-i2-1-i2-1-nr-1-i2-1-i2-1-nr-1-"       [9] "-1-i2-1-"                                    [10] "-1-nr-1-i3-1-qu-1-i2-1-i3-1-qu-1-nr-1-i2-1-" [11] "-1-nr-1-qu-1-qu-1-i2-1-" i want use regex detect particular strings substring precedes substring, but not directly preceding other substring.
for example, let's looking fa preceding ex. need match 1 in list. though fa has -1-i2-1-i2-1-i2-1- between , ex, fa still occurs before ex, hence match expected.
how can generic regex defined identifies strings substrings appear before substring in manner?
you may use grep.
x <- c("1-fa-1-i2-1-i2-1-i2-1-ex-1-i2-1-i3-1-fa-1-" ,"-1-i2-1-tr-1-") grepl("fa.*ex", x) #[1]  true false grep("fa.*ex", x) #[1] 1 
Comments
Post a Comment