fork download
  1. strs <- c("N(0, 1)", "N(N(0.1, 1), 1)", "N(U(0, 1), 1)", "N(0, T(0, 1))", "N(N(0, 1), N(0, 1))")
  2. p <- "(?:\\G(?!^)\\s*,\\s*|^N\\()\\K(?:\\d+|\\w+(\\([^()]*(?:(?1)[^()]*)*\\)))(?=\\s*,|\\)$)"
  3. res <- regmatches(strs, gregexpr(p, strs, perl=TRUE))
  4. res
Success #stdin #stdout 0.2s 39252KB
stdin
Standard input is empty
stdout
[[1]]
[1] "0" "1"

[[2]]
[1] "N(0.1, 1)" "1"        

[[3]]
[1] "U(0, 1)" "1"      

[[4]]
[1] "0"       "T(0, 1)"

[[5]]
[1] "N(0, 1)" "N(0, 1)"