Skip to contents

Combines a vector or list of regular expressions to a single one (by logical OR).

Usage

fuse_regex(..., .literal = FALSE)

Arguments

...

Regular expressions. All elements will be converted to type character before fusing. Dynamic dots are supported.

.literal

Whether or not the input should be interpreted literally instead of as regular expressions. If TRUE, all elements of ... are wrapped in the literal escape sequences \Q and \E.

Value

A character scalar.

See also

The rex package which provides an intuitive framework to build complex regular expressions.

Other string functions: as_chr(), as_comment_str(), as_line_feed_chr(), as_str(), capitalize_first(), dsv_colnames(), enum_str(), escape_lf(), prettify_nr(), prose_ls(), sentenceify(), wrap_chr()

Examples

# \donttest{
# perform some (nonsense) Jane Austen text extraction
regex <- c("My dear Jane",
           "make haste, ",
           "(?i)\\bevil")

stringr::str_subset(string = janeaustenr::prideprejudice,
                    pattern = pal::fuse_regex(regex))# }
#>  [1] "Jane, make haste and tell us; make haste, my love.\""                      "evil--a natural defect, which not even the best education can overcome.\""
#>  [3] "can have any evil tendency; and I am so far from objecting to dancing"     "evil.\""                                                                  
#>  [5] "to inevitable evils is the duty of us all; the peculiar duty of a"         "\"My dear Jane!\" exclaimed Elizabeth, \"you are too good. Your sweetness"
#>  [7] "understanding than I now do of her heart. My dear Jane, Mr. Collins is a"  "wish him all manner of evil. But my feelings are not only cordial"        
#>  [9] "however, was no evil to Elizabeth, and upon the whole she spent her time"  "travelling unimportant, distance becomes no evil. But that is not the"    
#> [11] "world; and no one could say how lasting an evil he might have inflicted."  "connection could not be so great an evil to my friend as to me. But"      
#> [13] "of pointing out to my friend the certain evils of such a choice. I"        "herself, was entirely insensible of the evil. Elizabeth had frequently"   
#> [15] "of particular, but of general evils, which I am now complaining. Our"      "over unavoidable evils, or augment them by anxiety, was no part of her"   
#> [17] "unsuitable a marriage, nor ever been so fully aware of the evils arising"  "greater evil might be apprehended, was likely to be hardened in all"      
#> [19] "good or evil must be done by him! Every idea that had been brought"        "kind of moral extractions from the evil before them."                     
#> [21] "\"You may well warn me against such an evil. Human nature is so prone"     "it sounds! And she was only sixteen last June. My dear Jane, I am in"     
#> [23] "an evil which had been brought on by himself. If he _had another_"         "\"My dear Jane, make haste and hurry down. He is come--Mr. Bingley is"    
#> [25] "representation of the evils attached to a connection with her, she dared"  "Elizabeth, and yourself, of what evils you may incur by a precipitate"    
#> [27] "there were other evils before her. She anticipated what would be felt"