Skip to main content
regexreplace(str, pattern, replace) replaces every match of pattern in str with replace. Uses RE2 regular expression syntax.

Signature

Example

Sanitize a git branch name for use as a Kubernetes namespace. Namespaces must be lowercase, alphanumeric, and hyphenated with no leading or trailing hyphens:
feature/My-Branch becomes feature-my-branch.

Notes

  • The pattern must be a valid RE2 expression. RE2 does not support lookahead or backreferences.
  • replace can include $1, $2, etc. to reference capture groups.
  • For simple string substitution without regular expressions, use replace.