Closed moodymudskipper closed 5 years ago
This is the way to do it, adapted from :
https://stackoverflow.com/a/41749376/2270475
s = c("{x} and {y=\\d{2}.*}", "{i} and {j=\\D{2}\\d{3}}") matched <- gregexpr("\\{(?>[^{}]|(?R))*\\}", s, perl = T) mapply(function(x,y) substring(x, y, y + attr(y, "match.length") - 1),s,matched) #> {x} and {y=\\d{2}.*} {i} and {j=\\D{2}\\d{3}} #> [1,] "{x}" "{i}" #> [2,] "{y=\\d{2}.*}" "{j=\\D{2}\\d{3}}"
Created on 2019-07-15 by the reprex package (v0.3.0)
This way also we don't need a dependency on stringr::str_match_all()
stringr::str_match_all()
done
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
This is the way to do it, adapted from :
https://stackoverflow.com/a/41749376/2270475
Created on 2019-07-15 by the reprex package (v0.3.0)
This way also we don't need a dependency on
stringr::str_match_all()