Learn R Programming

R.utils (version 2.12.3)

splitByPattern: Splits a single character string by pattern

Description

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.

Usage

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

Value

Returns a named character

vector with names equal to "TRUE"

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

Arguments

str

A single character string to be split.

pattern

A regular expression character string.

...

Not used.

Author

Henrik Bengtsson

See Also

Compare to strsplit().

Examples

Run this code

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

Run the code above in your browser using DataLab