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. Returnsnull if input string is null.
Examples
Example 1: Basic Text Replacement
Example 2: Remove Non-Numeric Characters
Example 3: Sanitize User Input
Example 4: Normalize Whitespace
Notes
- Returns
nullif input string isnull - 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
- text.regexGroups - Extract matches with capture groups
- text.indexOf - Find substring position
- text.format - Format strings with placeholders
Frequently Asked Questions
Does flex.text.replace use regex or literal matching?
Does flex.text.replace use regex or literal matching?
It uses regex pattern matching. If you want a literal match, escape any special regex characters in your pattern.
Does it replace all occurrences or just the first?
Does it replace all occurrences or just the first?
It replaces all occurrences (global replacement).