library("R.utils") rspCode <- "Hello <%=\"world\"%>" rspParts <- splitByPattern(rspCode, pattern="<%.*%>") cat(rspCode, "\n") print(rspParts)