1

I am trying to use a grep formula to search for at least one of the following terms in quotations in the code below in df$AllPrograms.

grep("Service & Product Provider (Partner;ACT)" | "Buildings (Prospect;INA)", df$AllPrograms)

This isn't working and I suspect it is because grep is not interpret ting the & ; and () as operators rather than characters.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Danny
  • 554
  • 1
  • 6
  • 17

1 Answers1

1

Use a double backslash "\" to escape these characters. This is because the backslash is an escape character in extended regex, but we need to "escape" the first backslash as well. Also, in your example code you have incorrectly specified the OR statement. Try:

grep("Service \\& Product Provider \\(Partner\\;ACT\\)|Buildings \\(Prospect\\;INA\\)", df$AllPrograms)

If there are many other patterns that you'd like to check for, take a look at this link here: grep using a character vector with multiple patterns

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
  • That worked. I updated the code to include the second program I want to search for using an or "|" statement. – Danny Apr 05 '18 at 21:51