1

I'm trying to split a string on single quotes.

str <- "Hello World, I'm splitting this string on 'Single Quotes'"
test <- strsplit(str , "'")

"Hello World, I'm splitting this string on " "Single Quotes"

I got both values above, but I want only the value Single Quotes. I know this is a basic question, but I'm new to R programming and trying to learn. Thanks in advance.

David Avendasora
  • 4,538
  • 1
  • 16
  • 15
RAAAAM
  • 3,378
  • 19
  • 59
  • 108
  • `strsplit(str , "'")[[1]][2]` ? or If you want regex, `regmatches(str, gregexpr("(?<=').*?(?=')", str, perl = TRUE))` – Sotos Nov 30 '17 at 12:50
  • Adapting a solution from [this answer](https://stackoverflow.com/a/13498914/1017276); `gsub(".*\\'(.*)\\'.*", "\\1", str)` – Benjamin Nov 30 '17 at 12:55
  • Thanks, i tried the above line of code, but the problem is when i include any other string between two single quotes, those string also present in the result. Ex: "Single quotes" "BLA BLA" "Second Single quotes" – RAAAAM Nov 30 '17 at 13:16
  • Please include all cases in your question – Sotos Nov 30 '17 at 13:41

0 Answers0