regex - Find all variants of word in R -


i have following words.

words <- c("hail(0.75)", "hail0.75", "hail0.88", "hail075", "hail1.00", "hail1.75", "hail100", "hail125", "hail1.75)", "hail150", "hail175", "hail200", "hail225", "hail275", "hail450", "hail088", "hail75", "hail80", "hail88")       [1] "hail(0.75)" "hail0.75"   "hail0.88"   "hail075"    "hail1.00"   "hail1.75"        [7] "hail100"    "hail125"    "hail1.75)"  "hail150"    "hail175"    "hail200"        [13] "hail225"    "hail275"    "hail450"    "hail088"    "hail75"     "hail80"         [19] "hail88"  

as can see, hail(0.75) repeated various typos/formatting (i.e. hail075, hail0.75)

how can find occurences of hail(0.75) including variants described above?

i've tried

grep("hail[0,7,5]"), words, value = t) [1] "hail0.75" "hail0.88" "hail075" "hail088" "hail75"

to find instances of hail contain numbers 075.
however, includes hail088 unwanted , excludes hail(0.75) wanted.

another option remove not digit numbers , use index:

idx <- gsub("[^[:digit:]]","",words) words[idx=="075"] [1] "hail(0.75)" "hail0.75"   "hail075" 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -