0

In R I am running into a problem with string matching for strings with this string: DRB1*07:01

Both grepl and str_detect report FALSE if I query this string on itself.

Here is the exact code I used:

str_detect("DRB1*07:01","DRB1*07:01") #returns FALSE
grepl("DRB1*07:01","DRB1*07:01") #returns FALSE

Shouldn't it return TRUE? Ideally, I want to be able to search with DRB1*07 and find DRB1*07:01 as a match, but cannot do so until I can at least match DRB1*07:01 with itself.

Thank you for any help!

Frank
  • 66,179
  • 8
  • 96
  • 180
  • You need to escape special characters in regular expressions. Use `grepl("DRB1\\*07:01","DRB1*07:01")` or `grepl("DRB1*07:01","DRB1*07:01", fixed=TRUE)`. Normally `*` means match the preceding character zero or more times. It does not mean a literal asterisk. – MrFlick Sep 27 '17 at 19:09
  • Thank you very much, fixed=TRUE solved the issue! – Brianna Paisley Oct 02 '17 at 16:44

0 Answers0