alnum_id: Generate ID strings

View source: R/string.R

alnum_idR Documentation

Generate ID strings

Description

Substitute certain (by default, non-alphanumeric) characters with dashes and remove extra dashes at both ends to generate ID strings.

Usage

alnum_id(x, exclude = "[^[:alnum:]]+")

Arguments

x

A character vector.

exclude

A (Perl) regular expression to detect characters to be replaced by dashes. By default, non-alphanumeric characters are replaced.

Value

A character vector of IDs.

Examples

x = c("Hello world 123!", "a  &b*^##c 456")
xfun::alnum_id(x)
xfun::alnum_id(x, "[^[:alpha:]]+")  # only keep alphabetical chars

xfun documentation built on Dec. 28, 2022, 1:11 a.m.