Splits a single character string by pattern. The main difference compared to strsplit() is that this method also returns the part of the string that matched the pattern. Also, it only takes a single character string.

# S3 method for default
splitByPattern(str, pattern, ...)

Arguments

str

A single character string to be split.

pattern

A regular expression character string.

...

Not used.

Value

Returns a named character

vector with names equal to "TRUE"

if element is a pattern part and "FALSE" otherwise.

Author

Henrik Bengtsson

See also

Compare to strsplit().

Examples


rspCode <- "<body>Hello <%=\"world\"%></body>"
rspParts <- splitByPattern(rspCode, pattern="<%.*%>")
cat(rspCode, "\n")
#> <body>Hello <%="world"%></body> 
print(rspParts)
#>            FALSE             TRUE            FALSE 
#>   "<body>Hello " "<%=\"world\"%>"        "</body>"