Skip to contents

This function replaces sensitive patterns in a text with a specified replacement string, or the default "[REDACTED]".

Usage

redact_pattern(text, pattern, replace_with = NULL)

Arguments

text

A character string containing the text to redact

pattern

A character string specifying the regular expression pattern to search for

replace_with

A character string specifying the replacement text to use. If NULL (default), the sensitive pattern is replaced with "[REDACTED]".

Value

A character string with sensitive patterns replaced with the specified replacement string

Examples

redact_pattern("My password is password123", "\\bpassword\\d*\\b")
#> [1] "My [REDACTED] is [REDACTED]"
redact_pattern("My API key is 1234-5678-9012-3456", "\\d{4}-\\d{4}-\\d{4}-\\d{4}", "[REDACTED]")
#> [1] "My API key is [REDACTED]"