Project

General

Profile

$regsubex » History » Version 7

Per Amundsen, 02/23/2023 07:29 PM

1 1 Per Amundsen
_Added in 1.9.0_
2
3 3 Per Amundsen
*$regsubex([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
Returns the substituted text.
8
9 5 Per Amundsen
_See also [[$regex]], [[$regsub]], [[$regml]], [[$regmlex]]. [[$regerrstr]]._
10 4 Per Amundsen
11 1 Per Amundsen
*Parameters*
12
13 7 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] | Optionally output the text to a %var or a &binvar. ([name] must be defined and returns the number of matches instead of the substituted text) |
20 1 Per Amundsen
21 7 Per Amundsen
The subtext evaluates identifiers before performing the substitution and special markers can be used to reference various parts of the result.
22
23 1 Per Amundsen
*Subtext*
24
25 7 Per Amundsen
table(ktable).
26
|*Character*|*Description*|
27
| \0 | Returns the number of matches. |
28
| \n | Returns the current match number. |
29
| \t | Returns the current match text (same as [[$regml]](\n)). |
30
| \a | Returns all matching items. |
31
| \A | Returns a non-spaced version of \a. |
32
| \@ | Returns the total number of matches. *(AdiIRC only)* |
33
| \1 \2 \N ... | Returns the Nth back-reference made for a given match |
34 1 Per Amundsen
35
36
*Example*
37
38
<pre>
39
; Find all lowercase 'a-z' characters and replace them with an uppercase character.
40
//echo -ag $regsubex(abcdefg,/([a-z])/g,$upper(\1))
41
</pre>