$regsub » History » Version 5
Per Amundsen, 01/16/2019 10:34 PM
1 | 1 | Per Amundsen | _Added in 1.9.0_ |
---|---|---|---|
2 | |||
3 | 3 | Per Amundsen | *$regsub([name], text, re, subtext, %var|&binvar)* |
4 | 1 | Per Amundsen | |
5 | Performs a regular [[Scripting_Regex|regular expression]] and then performs a substitution using subtext. |
||
6 | |||
7 | 3 | Per Amundsen | Returns the number of substitutions made, and assigns the result to %var or &binvar. |
8 | 1 | Per Amundsen | |
9 | 5 | Per Amundsen | _See also [[$regex]], [[$regsubex]], [[$regml]], [[$regmlex]]. [[$regerrstr]]._ |
10 | |||
11 | 1 | Per Amundsen | *Parameters* |
12 | |||
13 | [name] - Name of the search, which can later be referenced using [[$regml]]. (optional) |
||
14 | text - The text to search. |
||
15 | re - The [[Scripting_Regex|regular expression]] to perform. |
||
16 | subtext - Subtext to replace with. |
||
17 | 4 | Per Amundsen | %var|&binvar - Variable to assign the result to. |
18 | 1 | Per Amundsen | |
19 | *Example* |
||
20 | |||
21 | <pre> |
||
22 | alias Example { |
||
23 | 2 | Per Amundsen | ; Create a local variable. |
24 | 1 | Per Amundsen | var %Example |
25 | 2 | Per Amundsen | |
26 | 1 | Per Amundsen | ; Perform a search for '([O])' and replace it with 'o' and fill the variable %Example with the result. |
27 | noop $regsub(name,HellO WOrld,/([O])/g,o,%Example) |
||
28 | 2 | Per Amundsen | |
29 | ; Print the result. |
||
30 | 1 | Per Amundsen | echo -a $regml(name,0) : $regml(name,1) -- $regml(name,2) : %Example |
31 | } |
||
32 | </pre> |