Skip to main content

Description

Replaces all occurrences of a substring matching a regular expression pattern with a replacement string.

Syntax

Parameters

Returns

Type: string A new string with all pattern matches replaced by the replacement string. Returns null if input string is null.

Examples

Example 1: Basic Text Replacement

Output:

Example 2: Remove Non-Numeric Characters

Output:

Example 3: Sanitize User Input

Example 4: Normalize Whitespace

Output:

Notes

  • Returns null if input string is null
  • Uses global replacement (replaces all occurrences)
  • Pattern is treated as a regular expression
  • Useful for data cleaning, sanitization, and text transformation
  • Can use regex patterns for complex replacements

See Also

Frequently Asked Questions

It uses regex pattern matching. If you want a literal match, escape any special regex characters in your pattern.
It replaces all occurrences (global replacement).