Home > OS >  Write one regular expression for the list below to capture every instance of the name using R [dupli
Write one regular expression for the list below to capture every instance of the name using R [dupli

Time:09-21

Cathrin, Cathryn, Cathrinn, Cathrynn, Cathrine, Cathryne, Cathrinne, Cathrynne

so I tried this but I am not sure how to proceed.

reg_ex1 = c('Cathrin', 'Cathryn', 'Cathrinn', 'Cathrynn', 'Cathrine', 'Cathryne', 'Cathrinne', 'Cathrynne' )

Cathr(in|yn)(e|ne|n)

CodePudding user response:

You were very close, make the second part of the regex (e|ne|n) optional (?).

grepl('Cathr(in|yn)(e|ne|n)?', reg_ex1)
#[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
  • Related