extract_groups: extract_groups

View source: R/extract_groups.R

extract_groupsR Documentation

extract_groups

Description

This function takes a string input and applies the str_match function to extract the unique values of the capture group requested by .tag_group based on a regex given by .capture_groups.

Usage

extract_groups(.strings, .capture_groups = "(.+)_(.+)", .tag_group = 2)

Arguments

.strings

A character vector. Gives the strings to be extracted by .capture_groups.

Value

This function returns a character vector that is the result of matching the input .strings against the regex .capture_groups, selecting the desired capture group, .tag_groups, and returning the unique values of the result.

Examples

## Not run: 

char_vec <- c("extract", "a_b_c_d", "1_m.b-q_m")

# accept 1 or more matches in each capture group
extract_groups(char_vec, "(.+)_(.+)", 1)
extract_groups(char_vec, "(.+)_(.+)", 2)

# accept 0 or 1 matches in each capture group
extract_groups(char_vec, "(.?)a(.?)", 1)
extract_groups(char_vec, "(.?)a(.?)", 2)



## End(Not run)

tessaleejohnson/corclus documentation built on Oct. 11, 2022, 3:46 a.m.