0

Getting error while running grepl() to search for string match that has special characters.

choices <- c("2466|[BROAD] Midostaurin_{Rydapt} | tyrosine | FLT3_RX_FINAL", 
                     "2317|Inpatient or inpatient ER visit", 
                     "2465|[BROAD] Sorafenib{Nexavar} | tyrosine kinase inhibitor | VEGFR, FGF", 
                     "2464|[BROAD] Gilteritinib_{Xospata} | FLT3_RX_FINAL"
        )

grepl("[BROAD] Sorafenib{Nexavar} | tyrosine kinase inhibitor | VEGFR, FGF", choices)
sutsabs
  • 431
  • 2
  • 11
  • 1
    In regex, curly braces `{}` are used for quantifiers, e.g. `A{3}` means exactly 3 As, and `A{3,}` means 3 or more As. You are matching `{}` literally, so you need to escape them with two backslashes. (And your `[]` should be escaped as well, they are also special characters.) `choices <- c("2466|\\[BROAD\\] Midostaurin_\\{Rydapt\\} |...` – Gregor Thomas Jul 06 '23 at 19:56

0 Answers0