fork download
  1. x = "The \\' \\\\\\' \\\\\\\\'quick \\'cunning\\' brown' fox 'jumps up \\'and\\' over' the lazy dog"
  2. cat(x, sep="\n")
  3. gr <- gregexpr("(?<!\\\\)(?:\\\\{2})*\\K'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'", x, perl=TRUE)
  4. mat <- regmatches(x, gr)
  5. regmatches(x, gr) <- lapply(mat, gsub, pattern="\\s", replacement="_")
  6. cat(x, sep="\n")
  7.  
Success #stdin #stdout 0.16s 178496KB
stdin
Standard input is empty
stdout
The \' \\\' \\\\'quick \'cunning\' brown' fox 'jumps up \'and\' over' the lazy dog
The \' \\\' \\\\'quick_\'cunning\'_brown' fox 'jumps_up_\'and\'_over' the lazy dog