ket &lt;- function(x){
  gsub(&quot;\\[(.+?)\\]&quot;, &quot;\\1&quot;, x)
}

do_bracket &lt;- function(x){
  paste0(&quot;[&quot;, x, &quot;]&quot;)
}

do_split_rows &lt;- function(x){
  xx3 &lt;- strsplit(x, &quot;\\],&quot;)[[1]]
  for (i in 1:(length(xx3)-1))
    xx3[i] &lt;- paste(xx3[i], &quot;]&quot;)
  xx3
  xx3 &lt;- lapply(xx3, function(o) gsub(&quot;[[:space:]]*&quot;, &quot;&quot;, o))
  xx3
  xx4 &lt;- gsub(&quot;\\[+(.+?)\\]+&quot;, &quot;\\1&quot;, xx3)
  ## split by ,
  out &lt;- strsplit(xx