Project

General

Profile

$regsub » History » Revision 5

Revision 4 (Per Amundsen, 05/07/2017 11:15 PM) → Revision 5/6 (Per Amundsen, 01/16/2019 10:34 PM)

_Added in 1.9.0_ 

 *$regsub([name], text, re, subtext, %var|&binvar)* 

 Performs a regular [[Scripting_Regex|regular expression]] and then performs a substitution using subtext. 

 Returns the number of substitutions made, and assigns the result to %var or &binvar. 

 _See also [[$regex]], [[$regsubex]], [[$regml]], [[$regmlex]]. [[$regerrstr]]._ 

 *Parameters* 

 [name] - Name of the search, which can later be referenced using [[$regml]]. (optional) 
 text - The text to search. 
 re - The [[Scripting_Regex|regular expression]] to perform. 
 subtext - Subtext to replace with. 
 %var|&binvar - Variable to assign the result to. 

 *Example* 

 <pre> 
 alias Example { 
   ; Create a local variable. 
   var %Example 

   ; Perform a search for '([O])' and replace it with 'o' and fill the variable %Example with the result. 
   noop $regsub(name,HellO WOrld,/([O])/g,o,%Example) 

   ; Print the result. 
   echo -a $regml(name,0) : $regml(name,1) -- $regml(name,2) : %Example 
 } 
 </pre>