Method RegEx():replace() Foundation

Replaces matches with replacement text.

Syntax
:replace( <cSubject>, [<cReplacement>], [<lGlobal>] ) --> cString
Parameters
<cSubject>
The subject string to process.
<cReplacement>
The replacement text. This defaults to an empty string ("").
<lGlobal>
If .T. (true), replace all matches. When set to .F. (false), only the first match is replaced. Defaults to .F.
Return

The modified string with the replacements.

Description

Performs search and replace operations on the subject string. Can replace either the first match only or all matches depending on the <lGlobal> parameter. The replacement is literal text. Use the method :replaceCallback() when dynamic replacements are needed.

Replace

oRegEx := RegEx():create("\d+") 

// Replace first occurrence 
? oRegEx:replace("10 cats and 20 dogs", "X")  // "X cats and 20 dogs" 

// Replace all occurrences 
? oRegEx:replace("10 cats and 20 dogs", "X", .T.)  // "X cats and X dogs" 

oRegEx:destroy() 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.