Project

General

Profile

$regsub » History » Version 6

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