Format Matched Strings In a Text.
fmt_txt_at.RdFormat Matched Strings In a Text.
Arguments
- text
(character) text that contains strings that should be formatted
- pattern
regular expressions, or vector of regular expressions
- ...
<
dynamic-dots> format options pass toopenxlsx2::fmt_txt(). Can also be a lists of format options that has the same length aspattern.
Examples
shopping_list <- "apples x4, bag of flour, bag of sugar, milk x2"
# format the word 'bag' bold
fmt_txt_at(shopping_list, "\\bbag\\b", bold = TRUE)
#> fmt_txt string:
#> [1] "apples x4, bag of flour, bag of sugar, milk x2"
# format the x<nr> green and bold and the "bag of" in italic
fmt_txt_at(shopping_list,
c("x\\d+", "\\bbag of\\b"),
list(bold = TRUE, color = openxlsx2::wb_color("green")),
list(italic = TRUE)
)
#> fmt_txt string:
#> [1] "apples x4, bag of flour, bag of sugar, milk x2"