$regsub » History » Version 4
Per Amundsen, 05/07/2017 11:15 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 | *Parameters* |
||
10 | |||
11 | [name] - Name of the search, which can later be referenced using [[$regml]]. (optional) |
||
12 | text - The text to search. |
||
13 | re - The [[Scripting_Regex|regular expression]] to perform. |
||
14 | subtext - Subtext to replace with. |
||
15 | 4 | Per Amundsen | %var|&binvar - Variable to assign the result to. |
16 | 1 | Per Amundsen | |
17 | *Example* |
||
18 | |||
19 | <pre> |
||
20 | alias Example { |
||
21 | 2 | Per Amundsen | ; Create a local variable. |
22 | 1 | Per Amundsen | var %Example |
23 | 2 | Per Amundsen | |
24 | 1 | Per Amundsen | ; Perform a search for '([O])' and replace it with 'o' and fill the variable %Example with the result. |
25 | noop $regsub(name,HellO WOrld,/([O])/g,o,%Example) |
||
26 | 2 | Per Amundsen | |
27 | ; Print the result. |
||
28 | 1 | Per Amundsen | echo -a $regml(name,0) : $regml(name,1) -- $regml(name,2) : %Example |
29 | } |
||
30 | </pre> |