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
  • 9,229
  • 24
  • 74
  • 132

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
  • 69,796
  • 4
  • 95
  • 132