split_by_pattern(
x,
start_pattern = "^# |^## |---",
end_pattern = NULL,
name_list = TRUE,
include_start = FALSE
)
A character
vector.
A string with the start pattern (default:
"^# |^## |---"
).
A string with the end pattern. Use NULL
if there isn't
one (default: NULL
).
A logical
flag indicating if each
output item should have a name (default: TRUE
).
A logical
flag indicating if the
line flagged in the start pattern should be included in the split (default:
FALSE
).
A list with the split character vector.
Other string functions:
cutter()
,
replace_pattern()
x <- c(
"# Title 1",
"## Subtitle 1",
"Content 1",
"Content 2",
"# Title 2",
"## Subtitle 2",
"Content 3",
"Content 4"
)
split_by_pattern(
x,
start_pattern = "^# |^## |---",
end_pattern = NULL,
name_list = TRUE,
include_start = FALSE
)
#> $`# Title 1 [line 1]`
#> character(0)
#>
#> $`## Subtitle 1 [line 2]`
#> [1] "Content 1" "Content 2"
#>
#> $`# Title 2 [line 5]`
#> character(0)
#>
#> $`## Subtitle 2 [line 6]`
#> [1] "Content 3" "Content 4"
#>