0

A character string of interest can either be 'there are five apples' or 'there are five APPLES'

  strsplit(string, c('apples', 'APPLES'))

So I want to split by either apples or APPLES because I don't know if the string is going to have lower case or uppercase letters. But I tried the code above and it didn't work.

Adrian
  • 7,709
  • 23
  • 66
  • 119

1 Answers1

2

You could use the following which splits on case-insensitive "apples".

x <- 'there are five APPLES in this case'
unlist(strsplit(x, '(?i:apples)', perl=T))
# [1] "there are five " " in this case"  
hwnd
  • 67,942
  • 4
  • 86
  • 123