Binding operator

Binding operator Binding operator
This operator is a really ugly, poor and clueless attempt to reach at least 1% of the power of the Perl =~ operator :D It allows some complex string operations to be performed efficiently by operating directly on the left operand (in fact this is a lot faster in KVIrc since at least one step of parsing is skipped). Its basic syntax is: <left_operand> =~ <operation>[parameters] Where <operation> may be one of t, s and parameters depend on it. <left_operand> is the target of the <operation>. If <left_operand> is an array or dictionary, the <operation> is executed on each item they contain. Operation t is the transliteration. The complete syntax with parameters is: <left_operand> =~ t/<search characters>/<replacement characters>/ where <search characters> is a string of characters that are replaced with the corresponding characters in <replacement characters>. This operation can be also named y or tr (to preserve some compatibility with other languages).
%A=This is a test string echo %A %A=~ tr/abcdefghi/ABCDEFGHI/ echo %A
Operation s is the substitution. The complete syntax with parameters is: <left_operand> =~ s/<search pattern>/<replacement pattern>/[flags] where <search pattern> is an extended regular expression to be matched in the <left_operand> and <replacement string> is a special pattern that will replace any occurrence found. <search pattern> may contain parentheses to capture parts of the matched text. <replacement string> can contain the escape sequences \\N where N is a number between 1 and 9 to be replaced by the captured text. Please note that you need to double the backslashes in the search pattern since the KVS parser will first unquote the string and then pass it to the regexp engine. That's also why we use \\N and not \N. \\0 is a special escape that will be replaced by the entire match (is always valid!). [flags] may be a combination of the letters g, i and w. g causes the search to be global and not stop after the first occurrence of <search pattern>. i causes the search to be case insensitive. m causes the search to be case minimal (non-greedy). w causes the search pattern to be interpreted as a simple wildcard regular expression.
Examples
%A=This is a test string echo %A %A=~ s/([a-z])i([a-z])/\\1I\\2/ echo %A %A=~ s/([a-z])i([a-z])/\\1@\\2/gi echo %A
%a = "" %a << free echo %a %a .= bsd echo %a %a << rox echo %a %a <, but Linux is better! echo %a
See also
Operators

Index, Language Overview