Debian Codegraph @

man/alnum_id.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/string.R
3 \name{alnum_id}
4 \alias{alnum_id}
5 \title{Generate ID strings}
6 \usage{
7 alnum_id(x, exclude = "[^[:alnum:]]+")
8 }
9 \arguments{
10 \item{x}{A character vector.}
11
12 \item{exclude}{A (Perl) regular expression to detect characters to be
13 replaced by dashes. By default, non-alphanumeric characters are replaced.}
14 }
15 \value{
16 A character vector of IDs.
17 }
18 \description{
19 Substitute certain (by default, non-alphanumeric) characters with dashes and
20 remove extra dashes at both ends to generate ID strings. This function is
21 intended for generating IDs for HTML elements, so HTML tags in the input text
22 will be removed first.
23 }
24 \examples{
25 x = c("Hello world 123!", "a &b*^##c 456")
26 xfun::alnum_id(x)
27 xfun::alnum_id(x, "[^[:alpha:]]+") # only keep alphabetical chars
28 # when text contains HTML tags
29 xfun::alnum_id("<h1>Hello <strong>world</strong>!")
30 }