Skip to contents

This function redacts phone numbers in a given text by replacing them with a specified string.

Usage

redact_phone_numbers(text, replace_with = NULL)

Arguments

text

The text in which phone numbers are to be redacted.

replace_with

A string to replace the phone numbers with. It can either be a whole word like "[REDACTED]", or a single character like "*" that gets repeated based on how long the phone number detected is. Default is NULL, which uses the default value specified in the `replace_pattern()` function.

Value

A character vector with phone numbers redacted.

Examples

text <- "My phone number is (123) 456-7890. Please don't share it with anyone."
redacted_text <- redact_phone_numbers(text)
cat(redacted_text)
#> My phone number is [REDACTED]. Please don't share it with anyone.